Could someone please tell me how to edit a script in AutoHotkey?
I use a macro recorder, to perform several repetitive tasks, i.e. "MOVE UP n MOVE DOWN" many times, so I use to press the macro shortcut repeatedly. The issue is that in the macro recorder that I use if you assign a shortcut with a modifier to call a macro (i.e. Shift A), then you must release the modifier each time you want to perform the macro, so I usually have to (press Shift, press A, release Shift and release A), each time I want to call the macro, instead of just press Shift, hold it, and then press and release A many times. which is easier. I I am looking for an AutoHotKey script that could solve this issue, I have lots of this macros, so I can not create a bat or exe file for each one, I basically need a AutoHotkey script like:
if keystate, SHIFT, P
a::
send (Shift down)
send (a down)
send (Shift up)
send (a up)
or any other script that could send the Shift and A keys every time I press A but only if the Shift key is pressed.
I have been trying with loops, but I just don't know how to make it stop.
Consider that I need not to be obliged to release and press again "Shift + a" every time I want to call a macro, but also "Alt + a", and also "Alt + Win + a", each different combination call different macros. So it will be bad idea to set the "a" key to be always "Shift + a", because I need the "a" key to perform different macros according to which other modifier keys are pressed at same time.
The list of hotkeys that I use in this application are (everyone do something different, and it can not be replaced by any other hotkey)
Alt + A
Shift + A
Win + A
Alt + Shift + A
Win + Alt + A
and so on with most of the letters (S, D, Q, W, E, etc. and numbers 1, 2, 3,etc.) also:
Shift + Tab
Win + Tab
Alt + Capslock
Win + Alt + Capslock
(Its really annoying to got to release Shift and Tab, and press them both again, each time I want to run a macro, I run this macro many times repetitively) I think those are all the hotkeys, they all do different things that I run repetitively every time.
Please, I do need a script that would launch different actions pressing the same "a" key according to which other modifier keys are pressed at same time.
Hi Robert, I didn't understand quite well what you said, but I edited the script like this
#MaxThreadsPerHotkey 2
#SingleInstance Force
#installKeybdHook
#Persistent
AppName=MyKeys
Menu, Tray, Tip, %AppName%
Menu, Tray, Icon , Shell32.dll, 45, 1 ; 45, 28, 113, 74, 134
TrayTip, %AppName%, Started, 1
*a::
GoSub, MyGetKeyStateSub
If (MyGetKeyStateValue=0)
{
SendInput, a
}
Else
{
if( MyGetKeyStateValue & 1 > 0) ; Compare first bit
send {LAlt down}
send {d down}
send {LAlt up}
send {d up}
if( MyGetKeyStateValue & 10 > 0) ; compare second bit
MsgBox, RShift
if( MyGetKeyStateValue & 100 > 0) ; compare third bit
send {LAlt down}
send {d down}
send {LAlt up}
send {d up}
if( MyGetKeyStateValue & 1000 > 0)
MsgBox, RShift
if( MyGetKeyStateValue & 10000 > 0)
MsgBox, LAlt
if( MyGetKeyStateValue & 100000 > 0)
MsgBox, RAlt
if( MyGetKeyStateValue & 1000000 > 0)
MsgBox, LWin
if( MyGetKeyStateValue & 10000000 > 0)
MsgBox, RWin
if ( MyGetKeyStateValue & 00000011 > 0) ; If LCtrl AND LShift pressed
MsgBox, LCtrl AND LShift
}
Return
MyGetKeyStateSub:
MyGetKeyStateValue:=0
if getkeystate("LCtrl", P)
MyGetKeyStateValue+=1 ; set least significant bit
if getkeystate("RCtrl", P)
MyGetKeyStateValue+=2 ; set 2nd least significant bit, etc, etc.
if getkeystate("LShift", P)
MyGetKeyStateValue+=4
if getkeystate("RShift", P)
MyGetKeyStateValue+=8
if getkeystate("Lalt", P)
MyGetKeyStateValue+=16
if getkeystate("Ralt", P)
MyGetKeyStateValue+=32
if getkeystate("LWin", P)
MyGetKeyStateValue+=64
if getkeystate("RWin", P)
MyGetKeyStateValue+=128
Return
*d::
GoSub, MyGetKeyStateSub
If (MyGetKeyStateValue=0)
{
SendInput, d
}
Else
{
if( MyGetKeyStateValue = 1) ; LAlt
{
SendInput, {LAlt Down}d{LAlt Up}
Return
}
if( MyGetKeyStateValue = 4) ; LWin
{
SendInput, {LAlt Down}{LWin Down}d{LAlt Up}{LWin Up}
Return
}
}
Return
and open the program, and the same it didn't work, first time I press Alt D I get the macro, second time I press D holding the alt key, I get a plain D.
I was thinking about what you said relative to the XY problem, perhaps I should rebuild all my macros from HK4 (Hot Keyboard Pro 4) to AutoHotkey. There are lots of macros that I created with the help of the HK4 GUI, but the macros themselves are stored inside an xml script file, I opened this file once with a text editor and its huge!, How much time could take me to script all these macros inside AHK?
I have set like 25 variables that apply to every macro (like 200 macros) mostly are mouse movements, mouse clicks, copy selected text (number values) from floating windows inside an application, apply arithmetic operation to them and pasting the results inside the same boxes again (HK4 has and option that play keys, because otherwise it can't not paste inside the application), running depending on which software, which floating windows names, and which variables are enabled or disable (inverted condition), also have toggles macros that (toggle between two macros with one hotkey), I mean, how much it will take me to learn how to script all those kind of macros inside AHK?, I looked on internet, but its very hard to understand each posted case that do not apply exactly to what I intend to do, Thanks Robert, what do you suggest me? I mean, I would rebuild all my macros in AHK because inside AHK I do not have to release the modifier key to perform a macro many times simultaneously, What about Autoit its easier to learn? I read it had macrorecorder? Thanks.