4

I have some actions defined in an Autohotkey script and I want to run it
whenever I press SPACE+Alt+Q.

How can I do it?

I have read that space has some issues, because it is already used by AHK to confirm the abbreviations or something like that, but I really don't use abbreviations.

~Space & j::
   If GetKeyState("Alt") = 0
           Send {Left}
   Else
           Send +{Left}
Return

What suggestions do you have?

now I'm trying this that got from AHK forum, so far, its allow me to run the script continuosly without having to realease the space bar

; THIS IS THE FIRST PART OF MY SCRIPT, ITS FOR THE e, +e, d, +d HOTKEYS...
ARprecColPickerFn(a, b, c)
{
clipboard =  ; Start off empty to allow ClipWait to detect when the text has arrived.
MouseGetPos posX, posY
BlockInput, MouseMove
MouseClick, Left, a, b
Sleep 50
SendInput {Ctrl Down}{c Down}
SendInput {c Up}{Ctrl Up}
ClipWait, 2  ; Waits 3 secs for the clipboard to contain text
clipboard += %c%
SendInput {Ctrl Down}{v Down}
SendInput {v Up}{Ctrl Up}
Send {Enter}
BlockInput, MouseMoveOff
MouseMove %posX%, %posY%
}

e::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerLumY, 2)
return

+e::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerLumY, 1)
return

d::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerLumY, -2)
return

+d::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerLumY, -1)
return


; THIS IS THE SECOND PART OF THE SCRIPT, IS FOR THE Space & e, Space & !e, Space & d, Space & !d...
~$Space::
    KeyWait,Space,T0.2
    If (ErrorLevel)
    {
        HotstringsEnabled:=true
        KeyWait,Space
        HotstringsEnabled:=false
    }
        else
        Send {Space}    
Return
#If HotstringsEnabled
#Hotstring *

e::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerBluY, 4)
return

!e::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerBluY, 2)
return

d:
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerBluY, -4)
return

!d::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerBluY, -2)
#If

So far the script works fine, but I have an issue. the first part of the script, the one that use "d" as hotkey, it gets triggered whenever I press "space + d", how can I make both actions coexist together? (the one that is triggered by "d" and the other that its triggered by "space & d" Please any AHK superuser that could check it out, thanks advanced.

Btw, what does mean...

#Hotstring *

EDITED>>>>

In an Autohotkey script I would like Space Alt E to ADD FIVE, and Space Alt D to SUBTRACT FIVE, and Space E to ADD TEN, and Space D to SUBTRACT TEN.

I want to add or subtract consecutively and quickly, so I want to hold down Space Alt and then have distinct events when pressing E or D. e.g. SpaceHoldDown AltHoldDown Edown Eup Edown Eup Edown Eup would ADD FIVE 3 times.

Also sometimes I first press Space and then Alt (in order to hold them down before pressing E or D to ADD or SUBTRACT) and other times I press first Alt then Space, but in either case I would like to get the same result when pressing E or D afterwards. This is something my current script can't do, meaning I always have to take care to press first Space and then Alt before pressing E or D in order for the script to work, cuz if I press first Alt and then Space it wont work. I would like the script to work no matter in what order Space and Alt Key are pressed.

Finally I need the Space Key to keep its native function (not to be blocked) cuz it is used to navigate in the application.

Currently the script is working letting me hold down Space Alt and E or D consecutively in order to ADD or SUBTRACT multiple times, but it has the problems that I have to press first Space then Alt otherwise it won't work, also this whole peace of script must be placed at the very end of my AHK script cuz otherwise it will interfere with other subroutines.

LAST EDIT, THE CODE IM TRYING BASED ON JJHONSTON2 ANSWER...

#If WinActive("ahk_class xxx") || WinActive("ahk_class YYY")

    #If (GetKeyState("Alt", "P")) && (GetKeyState("Space", "P"))
        q::
            msgbox you typed Alt Space Q
    #If
#If    <----- do I need to put a second #If (turn off context sensitivity)?

but it doesn't work.

After testing, I have realized that I have to use #If and not If cuz the latter only will trigger the subroutine if I press Alt and Space AFTER I have pressed Q.

But using #If doesn't allow me to test 2 keys using the && operand. please would somebody know how to use the #If GetKeyState with 2 keys Space and Alt

Please notice that I do need to be able to hold down space and alt and press and release Q multiple times in order to ADD 10 consecutively, that's very important, that's why a workaround like this below is not usefull cuz it force me to release alt or space between subroutines (run it multiple times)

#If GetKeyState("Space", "P")
!q::    ;   The word UP may follow the name of a hotkey to cause the hotkey to fire upon release of the key rather than when the key is pressed down.
msgbox wttffff
Return
#If

#If GetKeyState("Alt", "P")
Space & q:: ;   The word UP may follow the name of a hotkey to cause the hotkey to fire upon release of the key rather than when the key is pressed down.
msgbox wttffff
Return
#If

thanks advanced.

4
  • the script above kinda works, the problem is that it can't run it two times consecutively, I mean, if I want to run the Space + Alt + j script for the second time, I necessarily have to release the space key (Space up) and press again (Space down) then (Alt down) and J, instead of just hold Space and Alt down, and press down and up J as many times as I want the script to be executed. Also I have problems when accidentally press the alt first and then the space, cuz its a windows default shortcut, how can I override it?? Thanks Advanced.
    – litu16
    Nov 24, 2016 at 22:13
  • Could you be more clear on what you desire to happen? Nov 25, 2016 at 1:54
  • Do you want to hold Space+Alt and then have distinct event happen when you press Q or J? Is it something like Space+Alt Q→J→J→Q→Q or Space+Alt Q→J (multiple Q/J presses or one each)? Nov 25, 2016 at 1:58
  • I would like Space Alt Q to ADD FIVE, and Space Alt A to SUBTRACT FIVE, and Space Q to ADD TEN, and Space A to SUBTRACT TEN. I want to add or subtract consecutively and quickly, so I want to hold down Space Alt and then have distinct even when pressing Q or A. e.g. SpaceHoldDown AltHoldDown Qdown Qup Qdown Qup Qdown Qup would ADD FIVE 3 times. Also sometimes I first press Space and then Alt (in order to hold them down) and other times I press first Alt then Space, but in either case I would like to get the same result when pressing Q or A afterwards. My current script can't do both.
    – litu16
    Jan 4, 2017 at 2:16

6 Answers 6

2

I am posting further because you continue to try different suggestions and combinations and are not just asking for someone else to write your script.

I am going to copy/paste/modify several key definition examples in hopes of giving you a feel for different ways this can be done (in ways which may or may not have been mentioned already), and hopefully give you a better understanding of the various logic combinations that can be used instead of just solving your particular key combination problem. Hopefully you will be able to figure it out if I do not address it directly.

Example: Trigger only if Space is pressed.

#If GetKeyState("Space", "P")   ; All hotkeys below won't trigger unless space is pressed
q::
    ToolTip % "Space+q pressed..."
    Sleep 500
    ToolTip
Return

!q::
    ToolTip % "Space+Alt+q pressed..."
    Sleep 500
    ToolTip
Return
#If

Example: Inspecific triggers for multiple modifier checks within the hotkey code.

#If WinActive("ahk_class xxx") || WinActive("ahk_class YYY")
*q::        ; * Triggers for all/multiple modifiers.  q keypress is discarded.

    If !(GetKeyState("Alt", "P") && GetKeyState("Space", "P"))
        Return  ; continue no further unless Alt+Space are also pressed.  q keypress is discarded

    ; This code below will execute for Alt+Space-q and also Alt+Space+Control+q (i.e., * modifiers that haven't been excluded via test above)
    ToolTip % A_ThisHotkey " pressed..."
    Sleep 500
    ToolTip
Return

Example: Manually send the keystroke (i.e., in-hotkey modifier filtering)

#If WinActive("ahk_class xxx") || WinActive("ahk_class YYY")
*q::        ; * Triggers for all/multiple modifiers

    If !(GetKeyState("Alt", "P") && GetKeyState("Space", "P")) {
        SendInput {Blind}q      ; send q keystroke and allow any pressed modifiers to stay in tact.  If Control is down, Control+q will get sent
        Return  ; continue no further unless Alt+Space are also pressed.  
    }

    ; This code below will execute for Alt+Space-q and also Alt+Space+Control+q (i.e., * modifiers that haven't been excluded via test above)
    ToolTip % A_ThisHotkey " pressed..."
    Sleep 500
    ToolTip
Return

Example: Keystroke gets sent to program regardless if you act on it or not.

#If WinActive("ahk_class xxx") || WinActive("ahk_class YYY")
~*q::       ; * Triggers for all/multiple modifiers; ~ allow passthrough so keystroke is not discarded

    If !(GetKeyState("Alt", "P") && GetKeyState("Space", "P"))
        Return  ; continue no further unless Alt+Space are also pressed.  q keypress has already passed through to program

    ; This code below will execute for Alt+Space-q and also Alt+Space+Control+q (i.e., * modifiers that haven't been excluded via test above)
    ToolTip % A_ThisHotkey " pressed..."
    Sleep 500
    ToolTip
Return

Example: Multiple definitions/actions in a single hotkey (works but not recommended implementation).

#If WinActive("ahk_class xxx") || WinActive("ahk_class YYY")
*q::        ; * Triggers for all/multiple modifiers; ~ allow passthrough so keystroke is not discarded

    If !GetKeyState("Space", "P")
        Return  ; continue no further unless Alt+Space are also pressed.  q keypress is discarded

    If (GetKeyState("Alt", "P") {
        ToolTip % "Alt+Space+q (and possibly other modifiers) pressed..."
        Sleep 500
        ToolTip
    } Else {
        ToolTip % "Space+q (and possibly other modifiers) pressed..."
        Sleep 500
        ToolTip
    }
Return

You can differentiate what keys are down inside of the hotkey definition and selectively execute distinct sets code, but general best practice is probably to use #If statements to determine when the hotkey code executes.

Don't use two #If's in a row... the hotkey definition is determined by the last sequential #If statement before the hotkey definition statement...

; Do Not Use...
#If WinActive("ahk_class xxx") || WinActive("ahk_class YYY")
#If (GetKeyState("Alt", "P")) && (GetKeyState("Space", "P"))    ; this voids the #If statement above

Should be as follows below.

; If ahk_class xxx or yyy, and if Alt+Space is also pressed...
#If (WinActive("ahk_class xxx") || WinActive("ahk_class YYY"))  && (GetKeyState("Alt", "P") && GetKeyState("Space", "P"))   
; ...
; code goes here
; ...
#IfWinActive ; this sets context for the next hotkeys back to default; only one statement needed; indentation is irrelevant

Note the use of grouping parens as needed for logical OR/AND combinations... you can get away without them in some cases but be careful to combine the statements carefully when mixing ANDs and ORs.

This statement can also be continued automatically on two lines (for style/readability) since the boolean operators are recognized as continuing the last line...

#If (WinActive("ahk_class xxx") || WinActive("ahk_class YYY"))  
&& (GetKeyState("Alt", "P") && GetKeyState("Space", "P"))
;q::    ; q hotkey without modifiers will never trigger here because Alt must be down to get this far
!q::    ; this will trigger
    ToolTip % "Space+Alt+q pressed..."
    Sleep 500
    ToolTip
Return
!d::
    ToolTip % "Space+Alt+d pressed..."
    Sleep 500
    ToolTip
Return
#If

Example: Split processing (inside/outside hotkey definition) (works but not recommended implementation)

#If (WinActive("ahk_class xxx") || WinActive("ahk_class YYY"))
!q::
    If GetKeyState("Space", "P") {
        ToolTip % "Space+Alt+q pressed..."
        Sleep 500
        ToolTip
    } Else {
        ToolTip % "Alt+q pressed..."
        Sleep 500
        ToolTip
    }
Return
#If

Example: All processing inside hotkey definition (works but not recommended implementation)

!q::
    If !(WinActive("ahk_class xxx") || WinActive("ahk_class YYY"))
        Return

    If GetKeyState("Space", "P") {
        ToolTip % "Space+Alt+q pressed..."
        Sleep 500
        ToolTip
    } Else {
        ToolTip % "Alt+q pressed..."
        Sleep 500
        ToolTip
    }
Return
#If

Final example with code split between hotkeys as needed and #If statements down-selecting to always have a certain class window active and Space pressed...

#Persistent
Return


#If (WinActive("ahk_class xxx") || WinActive("ahk_class YYY")) 
 && GetKeyState("Space", "P")   ; All hotkeys below won't trigger unless space is pressed

;!Space::Return     ; Optional. Kill the window system menu if present

q::
    ToolTip % "Space+q pressed..."
    Sleep 500
    ToolTip
Return

!q::
    ToolTip % "Space+Alt+q pressed..."
    Sleep 500
    ToolTip
Return

d::
    ToolTip % "Space+d pressed..."
    Sleep 500
    ToolTip
Return

!d::
    ToolTip % "Space+Alt+d pressed..."
    Sleep 500
    ToolTip
Return
#If

Note that this does not void the use of Space or Alt+Space as standalone keystrokes. For example if you press Space and then Alt and then a hotkey, it will send a Space before it executes the Alt+hotkey code. Similarly, if you press Alt+Space (say in a normal window) it will trigger the system window in the top left (Restore/Move/Size/Minimize/Maximize/Close). The hotkey functionality will still work, but the menu dropping down might be an annoyance (if you're not in a tool window that excludes this menu already), in which case you can also add an !Space::Return function to kill the functionality of Alt+Space while retaining the hotkey. In that case it should be added within the context block (relevant #If statement) so it only applies to that particular window.

There are multiple other ways to get code to execute for these key combinations as well, without using GetKeyState() (as noted in some of the other answers)--I am not going to reduplicate that information. You should be able to get some combination of answers posted to do what you want.

4
  • Hi JJohnston2 I read all your post, thanks for the info... Do Not Use... #If WinActive("ahk_class xxx") || WinActive("ahk_class YYY") [newline] #If (GetKeyState("Alt", "P")) && (GetKeyState("Space", "P")) ; this voids the #If statement above So I can't put one #If after another #If in contiguos lines, but what about if there are some code between them, like... #If statementA [newline] somecode [newline] #If statementB [newline] somecode [newline] #If [newline] #If does the #If statementB still voids the #If statementA in this case??? thanks advanced.
    – litu16
    Jan 5, 2017 at 15:17
  • about most of all other examples I already did varius tests and stated that I can't get the #If GetKeyState work with 2 keys, e.g... ; neither of these two lines work, the script will run (the syntax is ok) but it doesn't show the msgbox when Space Alt Q are pressed #If (GetKeyState("Space", "P") && GetKeyState("Alt", "P")) ;or #If GetKeyState("Space", "P") && GetKeyState("Alt", "P") q:: Sleep 200 msgbox you pressed alt space q Return #If Have you tested it?
    – litu16
    Jan 5, 2017 at 15:24
  • First comment: #If always overrides the last #If. Use boolean logic to combine and restate them if you need both to apply. Second comment: if you force the Alt key to be down with an #If conditional, you must check for !q:: or *q:: hotkey definitions, not just q::, as noted in the examples
    – JJohnston2
    Jan 5, 2017 at 15:34
  • #If (GetKeyState("Space", "P") && GetKeyState("Alt", "P")) doesn't work at all, and I can't relay on If GetKeyState cuz it doesn't work if other modifier keys where pressed prior the subroutine start. thanks for the #If bolean info though.
    – litu16
    Jan 5, 2017 at 17:19
3

Try this

Space:: Send {Space}

Space & j::
If GetKeyState("Alt")
   Send +{Left}
else
   Send {Left}
Return

Space & e::
If (GetKeyState("Alt") & GetKeyState("Shift"))
    ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerLumY, 1)
else
If GetKeyState("Alt")
    ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerBluY, 2)
else
    ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerBluY, 4)
return

Space & d::
If (GetKeyState("Alt") & GetKeyState("Shift"))
    ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerLumY, -1)
else
If GetKeyState("Alt")
    ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerLumY, -2)
else
    ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerBluY, -4)
return

    ARprecColPickerFn(a, b, c){
clipboard =  ; Start off empty to allow ClipWait to detect when the text has arrived.
MouseGetPos posX, posY
BlockInput, MouseMove
MouseClick, Left, a, b
Sleep 50
SendInput {Ctrl Down}{c Down}
SendInput {c Up}{Ctrl Up}
ClipWait, 2  ; Waits 3 secs for the clipboard to contain text
clipboard += %c%
SendInput {Ctrl Down}{v Down}
SendInput {v Up}{Ctrl Up}
Send {Enter}
BlockInput, MouseMoveOff
MouseMove %posX%, %posY%
}
4
  • thanks man, but it doesn't allow me to send the "Space & e" script multiple times continuously, e.g. press and hold space, while key down e key up e multiple times continuosly to run it multiple times. I solved by turning the script up and down. Thanks anyway.
    – litu16
    Nov 25, 2016 at 13:33
  • what about this? could you please check it out? superuser.com/questions/1149780/… Thanks advanced.
    – litu16
    Nov 25, 2016 at 18:24
  • Hi user3419297, could you please check this out? superuser.com/questions/1150394/autohotkey-remap-a-solid-key thanks advanced.
    – litu16
    Nov 28, 2016 at 0:15
  • 1
    I personally benefited a lot from this example. It basically established the <kbd>Space</kbd> key as a normal function key for setting up arbitrary keyboard mapping. I am personally suffering from hand cramp (at the left thumb) due to repeatedly pressing the Windows key; the template gave me a solution to map all my existing shortcuts to the spacebar.
    – llinfeng
    Apr 20, 2017 at 13:15
1

I think that you only can start hotkey with activation keys !{alt}, +{shift}, ^{ctrl}, win{#}. You could try something line this:

#if getKeyState("space")
!q:: run notepad.exe
#if

This will start notepad.exe but it will first run space button.

2
1

I just turned the script upside down, and in this way it allows to run it multiple times without unpress any key, even you can hold Space & e without realising to run it multiple times.

; THIS WAS THE SECOND PART OF THE SCRIPT, IS FOR THE Space & e, Space & !e, Space & d, Space & !d...
~$Space::
    KeyWait,Space,T0.2
    If (ErrorLevel)
    {
        HotstringsEnabled:=true
        KeyWait,Space
        HotstringsEnabled:=false
    }
        else
        Send {Space}    
Return
#If HotstringsEnabled
#Hotstring *

e::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerBluY, 4)
return

!e::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerBluY, 2)
return

d:
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerBluY, -4)
return

!d::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerBluY, -2)
#If



; THIS WAS THE FIRST PART OF MY SCRIPT, ITS FOR THE e, +e, d, +d HOTKEYS...
ARprecColPickerFn(a, b, c)
{
clipboard =  ; Start off empty to allow ClipWait to detect when the text has arrived.
MouseGetPos posX, posY
BlockInput, MouseMove
MouseClick, Left, a, b
Sleep 50
SendInput {Ctrl Down}{c Down}
SendInput {c Up}{Ctrl Up}
ClipWait, 2  ; Waits 3 secs for the clipboard to contain text
clipboard += %c%
SendInput {Ctrl Down}{v Down}
SendInput {v Up}{Ctrl Up}
Send {Enter}
BlockInput, MouseMoveOff
MouseMove %posX%, %posY%
}

e::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerLumY, 2)
return

+e::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerLumY, 1)
return

d::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerLumY, -2)
return

+d::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerLumY, -1)
return
1

In response to the updated post...

If you were to make the top hotkey conditional on not having Space be pressed the hotkey won't fire if space is held down. This would also need to be 'undone' as the script progresses lower, so there would also be an #IfWinActive statement to make this conditional not apply to further hotkey definitions below.

Top part of the script would look like this...

#If !GetKeyState("Space", "P")
+d::
ARprecColPickerFn(ARprecColPickerRestX, ARprecColPickerLumY, -1)
return

#IfWinActive
; THIS IS THE SECOND PART OF THE SCRIPT, IS FOR THE Space & e, Space & !e, Space & d, Space & !d...
~$Space::

For the other question...

#Hotstring *

... this places the * option in affect for all hotstrings defined past this line in the code.

From #Hostring Help Topic:

*(asterisk): An ending character (e.g. space, period, or enter) is not required to trigger the hotstring. For example:

:*:j@::[email protected]

Back to the general architecture of what you have working, I would just use #If conditionals on all of your hotkeys as IGRACH noted and do away with the complicated space-detecting loop that enables/disables hotkeys.

6
  • I will check it out ASAP, please could you check this question? superuser.com/questions/1150394/autohotkey-remap-a-solid-key
    – litu16
    Nov 28, 2016 at 0:14
  • BUT JJohnston2 please notice this below, this is the reason why the IGRACH solution doesn't work to me...
    – litu16
    Jan 4, 2017 at 2:37
  • I would like Space Alt Q to ADD FIVE, and Space Alt A to SUBTRACT FIVE, and Space Q to ADD TEN, and Space A to SUBTRACT TEN. I want to add or subtract consecutively and quickly, so I want to hold down Space Alt and then have distinct even when pressing Q or A. e.g. SpaceHoldDown AltHoldDown Qdown Qup Qdown Qup Qdown Qup would ADD FIVE 3 times. Also sometimes I first press Space and then Alt (in order to hold them down) and other times I press first Alt then Space, but in either case I would like to get the same result when pressing Q or A afterwards. My current script can't do both.
    – litu16
    Jan 4, 2017 at 2:37
  • Define your hotkey as the Q key then and use getKeyState conditionals to determine which modifiers are down. My post already has an example.
    – JJohnston2
    Jan 4, 2017 at 3:29
  • Hi JJohnston2, I reedited my question with all its isues here superuser.com/questions/1163155/… e.g. I need two modifiers (the alt and space keys no matter in which order are pressed) also I need the script to run continuosly consecutively by simply honding Alt Space and hit Q (many times) or A (many times). please could you check it out? thanks advanced.
    – litu16
    Jan 4, 2017 at 3:39
1
  • This AutoHotkey script should do what you require.
  • Tested on Windows 7.
  • In AutoHotkey, because of how keyboards are manufactured, various key combinations pose difficulties, in this case: a hotkey with two non-modifier keys (space and letters), and the Alt key. Other problem keys include CapsLock, Fn and the Win+L combination.
  • This script manages to get an awkward key combination to function quite smoothly.
  • This script works when Notepad is the active window. Use Ctrl+Q to remove the menu/sysmenu bars that interfere with Alt and Alt+Space, and use Ctrl+W to restore the menu bars.

-

;space alt e: +5
;space alt d: -5
;space e: +10
;space d: -10

;ctrl+q: prepare Notepad window (remove menu + sysmenu bars which interfere with alt)
;ctrl+w: restore Notepad window
;ctrl+e: set number to 0
;alt: blocked
;space: blocked
;ctrl+space: send space

vNum := 0

#IfWinActive,ahk_class Notepad

^e::
vNum := 0
Return

^q::
WinGet, hWnd, ID, A
WinGetClass, vWinClass, ahk_id %hWnd%
if vWinClass in Notepad
{
if (hMenu%hWnd% = "")
hMenu%hWnd% := DllCall("GetMenu", "uint", hWnd)
DllCall("SetMenu", "uint", hWnd, "uint", 0) ;hide menu bar
WinSet, Style, -0x80000, ahk_id %hWnd% ;WS_SYSMENU := 0x80000 ;hide system menu
}
Return

^w::
WinGet, hWnd, ID, A
WinGetClass, vWinClass, ahk_id %hWnd%
if vWinClass in Notepad
{
if !(hMenu%hWnd% = "")
DllCall("SetMenu", "uint", hWnd, "uint", hMenu%hWnd%) ;restore menu bar
WinSet, Style, +0x80000, ahk_id %hWnd% ;WS_SYSMENU := 0x80000 ;restore system menu
}
Return

Space & e::
if GetKeyState("Alt", "p")
vNum += 5
else
vNum += 10
ToolTip %vNum%
Return

Space & d::
if GetKeyState("Alt", "p")
vNum -= 5
else
vNum -= 10
ToolTip %vNum%
Return

Alt::
Return

Space::
Return

^Space::
SendInput {Space}
Return

#IfWinActive
3
  • man what did you do with the menus... I just wanted to trigger an action consecutively without having to release Alt or Space while pressing q down q up many times (in order to run it consecutively multiple times), also I need Space to keep its native function (the one the program uses it for. I stated that in the Question), and Alt should keep its native function too, I have tried something similar but it doesn't work, cuz it force me to release the Alt or Space key in order to run the subroutine multipe times. I suspect this script works the same, did you test it in that way?
    – litu16
    Jan 5, 2017 at 3:13
  • I got rid of the menus to prevent interference with Alt. Do the hotkeys run smoothly compared to other scripts?
    – vafylec
    Jan 5, 2017 at 3:29
  • -- I have tried something similar but it doesn't work, cuz it force me to release the Alt or Space key in order to run the subroutine multipe times. -- I wrote the script to avoid the need to release keys, also I removed the menu bars because they interfere with Alt. -- If my script works more smoothly than other scripts, then stage two is to bring back Alt and Space functionality if possible, without compromising smoothness.
    – vafylec
    Jan 5, 2017 at 3:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .