AutoHotkey - XButton1 Not Working With Control - scripting

I'm playing a game that requires you to hold down the control button to jump. What I wanna do is make it so that the XButton1 (Mouse Button 4) holds down the Control, then when I release XButton1, Control also releases.
It's odd because the XButton2 (Mouse Button 5) works, but XButton1 doesn't. The XButton1 is the 'back' button on my mouse, and that function works.
If I use this code: XButton:: Send {Lctrl Down}, that works, but the Control doesn't release until I click the Left Control again.
Does anyone know what I can do to make this work?
-Edit-
I just tried the following code: XButton1::Soundbeep and it worked, which is weird. But assigning the Control to it doesn't, but assigning it to XButton2 does.

Especially for modifier keys, you need to address both Up and Down as follows:
XButton1::Send {LCtrl Down}
XButton1 Up::Send {LCtrl Up}
Edit:
If the above doesn't work on that particular game, try:
XButton1::SendInput {LCtrl Down}
XButton1 Up::SendInput {LCtrl Up}
or
XButton1::SendPlay {LCtrl Down}
XButton1 Up::SendPlay {LCtrl Up}

Related

hover mouse over window and move mouse to resize window using autohotkey

I'm trying to creating a script that allows user to resize a window by hovering the mouse by pressing a keyboard shortcut without having to move a mouse to corner of a window each time.
This feature is currently available as part of BetterSnapTool for Mac OS X but I'm trying to develop the same feature for Windows 10 using AutoHotkey
I've developed a script for autohotkey that works well for most applications except for chrome and spotify (see below). It often gets stuck with the title bar menu open after hitting alt+space see video here
^+x::
MouseGetPos,,, hwnd
WinActivate, ahk_id %hwnd%
Send !{Space}
Sleep 1
Send m
sleep 1
send {down}
Return
Is there a more reliable way can do this?
I was able to solve this reliably by moving the mouse to the top right of the window next the minimize button and leaving the mouse button down while using blockinput.
Benefits:
This allows the the user to move the mouse freely to move the window.
It works for resizing as well.
being able to move windows if they're snapped fullscreen.
TIP: script has to be run as administrator for blockinput to work...
;Move Window Mode
^+x::
KeyWait Shift
KeyWait Alt
BlockInput, On
MouseGetPos,,, hwnd
WinActivate, ahk_id %hwnd%
WinGetPos, , , Width, Height, A
MouseMove, Width-186, 10
Click, down
Send {Shift Up}
Send {Ctrl Up}
BlockInput, Off
Return
;Resize Window Mode
^+z::
KeyWait Shift
KeyWait Alt
BlockInput, On
MouseGetPos,,, hwnd
WinActivate, ahk_id %hwnd%
WinGetPos, , , Width, Height, A
MouseMove, Width-3, Height-3
Click, down
Send {Shift Up}
Send {Ctrl Up}
BlockInput, Off
Return
The problem is that Sleep, 1 might not be enough time for the menu to appear on all applications.
The most reliable way to do it would be avoiding the menu altogether but that's quite some work to do through WinGetPos, MouseGetPos, and WinMove.
I guess you'll still be trying to use the menu, so my tip is to at least wait to be sure that the menu exists. You can do this getting the ProcessID of your hwnd, and wait so that first found window through that PID changes, that could be understood for us as a new window has appeared. In code means something like this:
WinGet, WinPID, PID, ahk_id %hwnd%
oldHwnd := WinExist("ahk_pid " WinPID)
Send !{Space}
newHwnd := oldHwnd
while (newHwnd == oldHwnd)
newHwnd := WinExist("ahk_pid " WinPID)
But you'd need some better exit conditions in case that the menu didn't happen to appear (a timeout?) to not get stuck there.
Still after that the Sleep, 1 might not be enough.

How to automate , to open a RSAToken application and simulate keystroke and to press Enter using AutoHotKey

I want to automate the following
1)Open the RSAToken Application
2)Simulate keystrokes to enter the PIN (say for eg : 223344 in that application)
3)Also to simulate the Enter keystroke upon entering the PIN
4)Copying passcode generated
i tried coding it by referring couple of articles but it was not working.
Following is the code
Run, "C:\Program Files (x86)\RSA SecurID Software Token\SecurID.exe"
;; 2222 is the PIN Code
Send, 2222
Sleep, 100
Send, {ENTER}
Sleep, 100
Send, ^c
Sleep, 100
Could anyone tell me , what am i missing ?
First of all, you need to wait for the application to start after running it. As I don't have the application, I can only suggest something like this:
WinWaitActive ahk_exe SecurID.exe
Then you need to copy the resulting code.
Ctrl+C only works if the code is selected, which it probably isn't. So Send ^c won't work.
Again, I don't have the application, but if it looks like this:
(source: rsa.com)
you need to move the keyboard focus to the Copy button and push it using the keyboard. That can probably be done either by
Send {Tab}{Enter}
or simply
Send {Enter}
if the button is already the default button.
In total, we have something like this:
Run, "C:\Program Files (x86)\RSA SecurID Software Token\SecurID.exe"
; Wait a while for the window to appear and become active.
timeoutSeconds:= 2
WinWaitActive ahk_exe SecurID.exe,, %timeoutSeconds%
if not ErrorLevel {
; The window is now active.
;; 2222 is the PIN Code
Send, 2222 ; Type the PIN code.
Sleep, 100
Send, {ENTER} ; Send the PIN code.
Sleep, 200 ; Wait for the program to generate the passcode.
Send {Tab} ; Move focus to the Copy button; this might not be needed.
Send {Enter} ; Press the Copy button.
Sleep, 100 ; Wait for the copy to happen; often unnecessary.
} else
MsgBox The window did not appear within %timeoutSeconds% seconds.
The general algorithm for writing a script like this is to first do the task manually using the keyboard only. When you can make that work, make a script that presses the same keys as you pressed manually.

Mouse button hotkeys only work once, not continual

I need to make an AutoHotkey script that performs some action when and while the mouse button is pressed, then finishes when the mouse button is released.
For (a very simplified) example:
LButton::
MouseGetPos x,y
MsgBox %x%-%y%
LButton Up::MsgBox Foobar
Replacing the LButton with a keyboard key (e.g., LWin) makes it work correctly and moving the mouse cursor updates as expected while the key is held down, but using the mouse button only performs the LButton action one time. I need the hotkey action to continue occurring until the button is no longer being held.
After a bunch of query-term tweaking, I found a page that gives sample scripts for autofire.
I wasn’t sure that was what I wanted (even though it made sense) because as I said, the sample script already works just fine for keys, but I gave it a shot anyway. I tweaked the sample a bit and now it works as desired. (Actually, it is very similar to a solution I had already been using, but now it absorbs the button event, which solves the underlying problem that I led me to trying the aforementioned script.)
Hopefully I picked good keywords in this post so that anyone else who finds themselves in the same situation can find the/a solution faster than I did.
#SingleInstance,force
CoordMode, Mouse, Screen
LButton::
While GetKeyState("LButton","p") {
MouseGetPos x,y
Tooltip %x%/%y%
Sleep 75
}
return
LButton Up::
Tooltip Foobar
return

Auto Hot Key - Holding down one key holds down 2 different keys

So I've used AutoHotKey to disable the AppsKey (the button on the keyboard which brings up the right-click menu). But I thought I could put it to better to use, and am trying to get it so that while I'm holding down the AppsKey the computer thinks I'm holding down Shift & Control instead.
I've been reading through the Command List but can't see anything for AppsKey down & up. Would anyone be able to share anything to enable me to do this?
Thanks
I don't understand what your problems are, but this little piece of code works for me:
AppsKey::Send, {SHIFT down}{CTRL down}
AppsKey up::Send, {CTRL up}{SHIFT up}
As you can see, there is an AppsKey up. Down on the other hand doesn't exist for hotkeys. In this example, the first hotkey triggers when AppsKey is pressed (that is, it triggers as soon as you hit it). The second hotkey triggers when it is released.

AutoHotkey background clicking and typing

I'm trying to use AutoHotkey to do some background clicking and typing while I'm doing other stuff in the foreground.
I've gotten used to Send but I haven't figured out how ControlSend works yet. Can anyone give me an example using something simple like MSPaint in the background and changing the color of paint.
Is this even possible to do? I have a script currently that pulls from daily Excel report, assigns each row a variable and punches it into another program, but I need it to click and type some canned messages as well.
The first question should probably be why use mouse control? Keyboard control is sooo much easier and often more reliable. What is it that you try to do with a mouseclick that can't be done through keyboard commands?
Also mouse clicks normally activate the hidden app.
OK you wanted an example...
+Home:: ;Shift + Home = stop/start radio
SetControlDelay -1
ControlClick, x384 y143, Radioplayer
Return
Here i click on the play/pause button of a streaming radioplayer. The mouse coordinates are found with the aforementioned Windows Spy and the title of the browser (you might have to use SetTitleMatchMode). Why not look at the AutoHotKey Command list and check out the examples there....
Let me know if this is (roughly) what you are looking for....
SendMode Input ; Recommended for new scripts
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTitleMatchMode, 2 ; A window's title can contain the text anywhere
!F1:: ; Press Alt F1 to execute
IfWinExist, Microsoft Excel
{
ControlSend ,, 1000{Enter}{Down}, Microsoft Excel
}
return
Here is some code I used to first record the mouse position (relative mouse position did not work since the window was tiled and the click position could be changed by moving the tiles). Immediately after that I click the mouse at the recorded position (and redo this later on in the code as well).
SplashTextOn, 200, 100, Script Preparations, Please Click on the Person `"Search Term`" link (1) in SAP. ; Show new instructions to the user
WinMove, Script Preparations,, (A_ScreenWidth/2)-150, (A_ScreenHeight/2)-200 ; Move the text instructions window with the name "Script Preparations" 150 pixels right of the center of the screen and 200 pixels up SoundBeep 600, 300 ; Wake up user
; From here on the left mouse button will temporarily be disabled
Hotkey, LButton, on ; Turn Left Mouse Button OFF, to capture the Mouse click
KeyWait, LButton, D ; Wait for LeftMouseButton click Down
MouseGetPos, xposS ,yposS ; Store the position where the mouse was clicked (Search Box)
MouseClick, left, %xposS% ,%yposS% ; Perform the mouse click on the captured mouse location
Hope this helps.
In your situation, I assume that you only need to determine the mouse position with Window Spy.