Hello All
I need Spacebar single press to send regular Space as usual
Spacebar long press to act as if I am holding Alt
When I release Spacebar, Alt is released
Thanks
spacebar long press as modifier
Re: spacebar long press as modifier
Code: Select all
*Space::
Send {Blind}{Alt Down}
KeyWait, Space ; waits for Space to be released
return
*Space Up::
Send {Blind}{Alt Up}
If (A_PriorHotKey = "*Space" AND A_TimeSincePriorHotkey < 300)
Send {Blind}{Space}
return
Re: spacebar long press as modifier
Welcome to this AutoHotkey forum!
Code: Select all
#Requires AutoHotkey v1.1.33
*Space::
KeyWait Space, T.3
If ErrorLevel {
SetKeyDelay -1
SendEvent {Blind}{Alt DownR}
KeyWait Space
SendEvent {Blind}{Alt up}
} Else Send {Space}
Return
Re: spacebar long press as modifier
Thank you!
only problem is, when I hold spacebar and quickly tap a letter, it sends the letter, not Alt+letter
therefore I would have to struggle and hold myself from quickly pressing the letter
only problem is, when I hold spacebar and quickly tap a letter, it sends the letter, not Alt+letter
therefore I would have to struggle and hold myself from quickly pressing the letter
Re: spacebar long press as modifier
The first script doesn't have this problem,
but it presses Alt while regular typing, when I press space, not hold it
therefore instead of typing a letter I fire a hotkey
but it presses Alt while regular typing, when I press space, not hold it
therefore instead of typing a letter I fire a hotkey
Re: spacebar long press as modifier
Code: Select all
#Requires AutoHotkey v1.1.33
Global pressed := False
ih := InputHook("I"), ih.KeyOpt("{All}", "+N")
ih.OnKeyDown := Func("altSend")
Space::
ih.Start()
KeyWait Space
Return
Space Up::
ih.Stop(), pressed := False
If (ih.Input = "")
Send {Space}
Return
altSend(ih, vk, sc) {
Send % (pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}"
If !pressed {
Send {Alt up}
pressed := True
}
}
Re: spacebar long press as modifier
Thank you, tried this but it doesn't seem to send Alt at all...
I am even with On-Screen Keyboard and I don't see alt firing at all...
I am even with On-Screen Keyboard and I don't see alt firing at all...
Re: spacebar long press as modifier
It works here. Check the
KeyHistory. Test in Notepad. I was able to activate the various menu items there.
![Arrow :arrow:](./images/smilies/icon_arrow.gif)
Re: spacebar long press as modifier
I tested in notepad, couldn't activate alt using spacebar... also in no other software. I don't know why it works for you but not for me
GEV could you test it please?
GEV could you test it please?
Re: spacebar long press as modifier
I tested some more, it works only one time, after I run the script
and it doesn't work the second time and on
and it doesn't work the second time and on
Re: spacebar long press as modifier
Close other scripts first. Use only this script with no changes and no other code.
What does your KeyHistory show?
What does your KeyHistory show?
Re: spacebar long press as modifier
I did close all the others...
002: pressed := False
003: ih := InputHook("I"), ih.KeyOpt("{All}", "+N")
004: ih.OnKeyDown := Func("altSend")
006: Return (8.61)
007: ih.Start()
008: KeyWait,Space (0.27)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.03)
019: if !pressed
020: Send,{Alt up} (0.02)
021: pressed := True
022: }
023: } (0.50)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (1.51)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.20)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.19)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.25)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.01)
019: if !pressed
023: } (0.16)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.01)
019: if !pressed
023: } (0.20)
012: ih.Stop(), pressed := False
013: if (ih.Input = "")
002: pressed := False
003: ih := InputHook("I"), ih.KeyOpt("{All}", "+N")
004: ih.OnKeyDown := Func("altSend")
006: Return (8.61)
007: ih.Start()
008: KeyWait,Space (0.27)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.03)
019: if !pressed
020: Send,{Alt up} (0.02)
021: pressed := True
022: }
023: } (0.50)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (1.51)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.20)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.19)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.25)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.01)
019: if !pressed
023: } (0.16)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.01)
019: if !pressed
023: } (0.20)
012: ih.Stop(), pressed := False
013: if (ih.Input = "")
Re: spacebar long press as modifier
I would check your key history, which is not shown here. Do not use on-screen keyboard in your test. What key sequence are you testing in Notepad?
Re: spacebar long press as modifier
got it, here it is
I am pressing ctrl+Q over and over
the first time it fures alt+Q and then it fires just Q
spacebar keeps being pressed, I am not releasing it
002: pressed := False
003: ih := InputHook("I"), ih.KeyOpt("{All}", "+N")
004: ih.OnKeyDown := Func("altSend")
006: Return (11.84)
007: ih.Start()
008: KeyWait,Space (0.13)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.03)
019: if !pressed
020: Send,{Alt up} (0.01)
021: pressed := True
022: }
023: } (1.36)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.01)
019: if !pressed
023: } (0.36)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.01)
019: if !pressed
023: } (0.25)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.19)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.20)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.17)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.01)
019: if !pressed
023: } (0.22)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.19)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.20)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.27)
012: ih.Stop(), pressed := False
013: if (ih.Input = "")
015: Return
009: Return (6.92)
I am pressing ctrl+Q over and over
the first time it fures alt+Q and then it fires just Q
spacebar keeps being pressed, I am not releasing it
002: pressed := False
003: ih := InputHook("I"), ih.KeyOpt("{All}", "+N")
004: ih.OnKeyDown := Func("altSend")
006: Return (11.84)
007: ih.Start()
008: KeyWait,Space (0.13)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.03)
019: if !pressed
020: Send,{Alt up} (0.01)
021: pressed := True
022: }
023: } (1.36)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.01)
019: if !pressed
023: } (0.36)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.01)
019: if !pressed
023: } (0.25)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.19)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.20)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.17)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.01)
019: if !pressed
023: } (0.22)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.19)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.20)
018: Send,(pressed ? "" : "{Alt down}") "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}" (0.02)
019: if !pressed
023: } (0.27)
012: ih.Stop(), pressed := False
013: if (ih.Input = "")
015: Return
009: Return (6.92)
Re: spacebar long press as modifier
Window: C:\Users\genad\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\spaceAlt.ahk - AutoHot
Keybd hook: yes
Mouse hook: no
Enabled Timers: 0 of 0 ()
Interrupted threads: 0
Paused threads: 0 of 0 (0 layers)
Modifiers (GetKeyState() now) =
Modifiers (Hook's Logical) =
Modifiers (Hook's Physical) =
Prefix key is down: no
NOTE: To disable the key history shown below, add the line "#KeyHistory 0" anywhere in the script. The same method can be used to change the size of the history buffer. For example: #KeyHistory 100 (Default is 40, Max is 500)
The oldest are listed first. VK=Virtual Key, SC=Scan Code, Elapsed=Seconds since the previous event. Types: h=Hook Hotkey, s=Suppressed (blocked), i=Ignored because it was generated by an AHK script, a=Artificial, #=Disabled via #IfWinActive/Exist, U=Unicode character (SendInput).
VK SC Type Up/Dn Elapsed Key Window
-------------------------------------------------------------------------------------------------------------
20 039 h d 2.75 Space снег.rtf [Compatibility Mode] - Word
51 010 s d 0.41 q
A4 038 i d 0.00 LAlt
51 010 i d 0.02 q
51 010 i u 0.00 q
A4 038 i u 0.02 LAlt
51 010 s u 0.16 q
51 010 s d 0.89 q
51 010 i d 0.00 q
51 010 i u 0.00 q
51 010 s u 0.13 q
51 010 s d 0.11 q
51 010 i d 0.00 q
51 010 i u 0.00 q
51 010 s u 0.08 q
51 010 s d 0.11 q
51 010 i d 0.00 q
51 010 i u 0.00 q
51 010 s u 0.08 q
51 010 s d 0.09 q
51 010 i d 0.00 q
51 010 i u 0.02 q
51 010 s u 0.09 q
51 010 s d 0.11 q
51 010 i d 0.00 q
51 010 i u 0.00 q
51 010 s u 0.11 q
51 010 s d 0.09 q
51 010 i d 0.00 q
51 010 i u 0.00 q
51 010 s u 0.09 q
51 010 s d 0.09 q
51 010 i d 0.00 q
51 010 i u 0.00 q
51 010 s u 0.13 q
20 039 h u 0.13 Space
Press [F5] to refresh.
Keybd hook: yes
Mouse hook: no
Enabled Timers: 0 of 0 ()
Interrupted threads: 0
Paused threads: 0 of 0 (0 layers)
Modifiers (GetKeyState() now) =
Modifiers (Hook's Logical) =
Modifiers (Hook's Physical) =
Prefix key is down: no
NOTE: To disable the key history shown below, add the line "#KeyHistory 0" anywhere in the script. The same method can be used to change the size of the history buffer. For example: #KeyHistory 100 (Default is 40, Max is 500)
The oldest are listed first. VK=Virtual Key, SC=Scan Code, Elapsed=Seconds since the previous event. Types: h=Hook Hotkey, s=Suppressed (blocked), i=Ignored because it was generated by an AHK script, a=Artificial, #=Disabled via #IfWinActive/Exist, U=Unicode character (SendInput).
VK SC Type Up/Dn Elapsed Key Window
-------------------------------------------------------------------------------------------------------------
20 039 h d 2.75 Space снег.rtf [Compatibility Mode] - Word
51 010 s d 0.41 q
A4 038 i d 0.00 LAlt
51 010 i d 0.02 q
51 010 i u 0.00 q
A4 038 i u 0.02 LAlt
51 010 s u 0.16 q
51 010 s d 0.89 q
51 010 i d 0.00 q
51 010 i u 0.00 q
51 010 s u 0.13 q
51 010 s d 0.11 q
51 010 i d 0.00 q
51 010 i u 0.00 q
51 010 s u 0.08 q
51 010 s d 0.11 q
51 010 i d 0.00 q
51 010 i u 0.00 q
51 010 s u 0.08 q
51 010 s d 0.09 q
51 010 i d 0.00 q
51 010 i u 0.02 q
51 010 s u 0.09 q
51 010 s d 0.11 q
51 010 i d 0.00 q
51 010 i u 0.00 q
51 010 s u 0.11 q
51 010 s d 0.09 q
51 010 i d 0.00 q
51 010 i u 0.00 q
51 010 s u 0.09 q
51 010 s d 0.09 q
51 010 i d 0.00 q
51 010 i u 0.00 q
51 010 s u 0.13 q
20 039 h u 0.13 Space
Press [F5] to refresh.
Re: spacebar long press as modifier
Perhaps:
Code: Select all
#Requires AutoHotkey v1.1.33
Global pressed := False
ih := InputHook("I"), ih.KeyOpt("{All}", "+N")
ih.OnKeyDown := Func("altSend")
Space::
ih.Start()
KeyWait Space
Return
Space Up::
ih.Stop()
If (ih.Input = "")
Send {Space}
Else Send {Alt up}
Return
altSend(ih, vk, sc) {
If !GetKeyState("Alt")
Send {Alt down}
Send % "{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}"
}
Re: spacebar long press as modifier
this works well the first time (right after I run the script)
but after I release the spacebar and press it again, it doesn't work anymore
here is the sequence I am pressing: spacebar down, q, q, spacebar up, spacebar down, q, q, spacebar up
and this is what the script actually does:
20 039 h u 1.05 Space
A4 038 i u 0.00 LAlt
20 039 h d 0.45 Space
51 010 s d 0.45 q
51 010 s u 0.16 q
51 010 s d 0.22 q
51 010 s u 0.13 q
20 039 h u 0.09 Space
A4 038 i u 0.00 LAlt
but after I release the spacebar and press it again, it doesn't work anymore
here is the sequence I am pressing: spacebar down, q, q, spacebar up, spacebar down, q, q, spacebar up
and this is what the script actually does:
20 039 h u 1.05 Space
A4 038 i u 0.00 LAlt
20 039 h d 0.45 Space
51 010 s d 0.45 q
51 010 s u 0.16 q
51 010 s d 0.22 q
51 010 s u 0.13 q
20 039 h u 0.09 Space
A4 038 i u 0.00 LAlt
Re: spacebar long press as modifier
Hmm, that's strange. Your key history is showing that your LAlt is not being sent down. I do not know why, because the script should send it down upon any key press, if Space is held. When I test in Notepad with Space+F+X, I see the following.
Thus, I am not able to reproduce your problem. Others may have additional ideas for you here. Ensure that all other scripts are closed during your testing.
If you are holding modifier keys, or modifier keys are down, then the hotkey will not be triggered. This can typically be corrected by adding a wildcard (*) to the hotkeys.
Thus, I am not able to reproduce your problem. Others may have additional ideas for you here. Ensure that all other scripts are closed during your testing.
If you are holding modifier keys, or modifier keys are down, then the hotkey will not be triggered. This can typically be corrected by adding a wildcard (*) to the hotkeys.
Re: spacebar long press as modifier
there is a misunderstanding between us
the first time everything works fine, here is what I get the first time (right after I activate the script)
20 039 h d 0.03 Space
46 021 s d 0.02 f
A4 038 i d 0.00 LAlt
46 021 i d 0.01 f
46 021 i u 0.00 f
46 021 s u 0.11 f
58 02D d 0.64 x
58 02D i d 0.00 x
58 02D i u 0.00 x
58 02D u 0.11 x Notepad
20 039 h u 0.73 Space
A4 038 i u 0.00 LAlt
but this is what I get on the SECOND time (don't reload the script)
try it, I am sure you will see the same results on the second time
20 039 h d 17.16 Space *New Text Document.txt - Notepad
20 039 h d 0.50 Space
46 021 s d 0.02 f
46 021 s u 0.11 f
58 02D s d 0.55 x
58 02D s u 0.11 x
20 039 h u 0.16 Space
A4 038 i u 0.00 LAlt
the first time everything works fine, here is what I get the first time (right after I activate the script)
20 039 h d 0.03 Space
46 021 s d 0.02 f
A4 038 i d 0.00 LAlt
46 021 i d 0.01 f
46 021 i u 0.00 f
46 021 s u 0.11 f
58 02D d 0.64 x
58 02D i d 0.00 x
58 02D i u 0.00 x
58 02D u 0.11 x Notepad
20 039 h u 0.73 Space
A4 038 i u 0.00 LAlt
but this is what I get on the SECOND time (don't reload the script)
try it, I am sure you will see the same results on the second time
20 039 h d 17.16 Space *New Text Document.txt - Notepad
20 039 h d 0.50 Space
46 021 s d 0.02 f
46 021 s u 0.11 f
58 02D s d 0.55 x
58 02D s u 0.11 x
20 039 h u 0.16 Space
A4 038 i u 0.00 LAlt
Re: spacebar long press as modifier
An improvement is below.
An alternative is below, but I prefer the script above that uses InputHook.
Code: Select all
#Requires AutoHotkey v1.1.33
ih := InputHook("IM"), ih.KeyOpt("{All}", "+N")
ih.OnKeyDown := Func("altSend")
Space::
ih.Start()
KeyWait Space
Return
*Space Up::
ih.Stop()
Send % ih.Input = "" ? "{Space}" : "{Alt up}"
Return
altSend(ih, vk, sc) {
Send % GetKeyState("Alt") ? "" : "{Alt down}"
Send % "{Blind}{" GetKeyName(Format("vk{:x}sc{:x}", vk, sc)) "}"
}
Code: Select all
#Requires AutoHotkey v1.1.33
$Space::
$!Space::
Send {Alt down}
KeyWait Space
Send % "{Alt up}" (A_PriorKey = "Space" ? "{Esc} " : "")
Return
Who is online
Users browsing this forum: sirksel and 278 guests