For example:
- I hold s
- I press and release d while holding s
- s continues functioning after releasing d
Is there a way to make that work?
Hold Key While Pressing Other Keys Without The Held Key Stopping?
Re: Hold Key While Pressing Other Keys Without The Held Key Stopping?
Hallo,
try:
try:
Code: Select all
s::
While, GetKeyState("s","P")
{
ToolTip, s: %A_Index%
Sleep, 200
}
Return
d::
While, GetKeyState("d","P")
{
ToolTip, d: %A_Index%
Sleep, 200
}
Return
Re: Hold Key While Pressing Other Keys Without The Held Key Stopping?
White, GetKeyState should be avoided (https://autohotkey.com/boards/viewtopic.php?t=19745). The same thing can be done with SetTimer. I didn't understand exactly what the ops meant by what he said. But let's assume RohWedder is right.Rohwedder wrote:Hallo,
try:Code: Select all
s:: While, GetKeyState("s","P") { ToolTip, s: %A_Index% Sleep, 200 } Return d:: While, GetKeyState("d","P") { ToolTip, d: %A_Index% Sleep, 200 } Return
Code: Select all
Toggle := 0
Toggle2 := 0
Svar := 0
Dvar := 0
s::
Svar++
Toggle := !Toggle
If Toggle
SetTimer, Spress, 0
Else {
SetTimer, Spress, Off
S := 0
}
return
d::
Dvar++
Toggle2 := !Toggle2
If Toggle2
SetTimer, Dpress, 0
Else {
SetTimer, Dpress, Off
D := 0
}
return
Spress:
If not Toggle
SetTimer, S, Off
Else {
ToolTip, s : %Svar%
Sleep, 200
ToolTip
}
return
Dpress:
If not Toggle2
SetTimer, D, Off
Else {
ToolTip, d : %Dvar%
Sleep, 200
ToolTip
}
return
esc:: ExitApp
I am your average ahk newbie. Just.. a tat more cute.
Re: Hold Key While Pressing Other Keys Without The Held Key Stopping?
Evilc's post from that link only seems to work if you don't change the strings (e.g. if ~a::a , but not if ~a::b (or any other character/s)).Nwb wrote: While, GetKeyState should be avoided (https://autohotkey.com/boards/viewtopic.php?t=19745). The same thing can be done with SetTimer. I didn't understand exactly what the ops meant by what he said. But let's assume RohWedder is right.
Code
etc...
As for your code, it wouldn't run at all. I was able to run it with some modifications. However, even then, it didn't seem to function as suggested.
Modification:
Code: Select all
Toggle := 0
Toggle2 := 0
S := 0
D := 0
s::
S++
Toggle := !Toggle
If Toggle
SetTimer, S, 0
Else {
SetTimer, S, Off
S := 0
}
If not Toggle
SetTimer, S, Off
Else {
ToolTip, s: %S%
Sleep, 50
}
return
d::
D++
Toggle2 := !Toggle2
If Toggle2
SetTimer, D, 0
Else {
SetTimer, D, Off
D := 0
}
If not Toggle2
SetTimer, D, Off
Else {
ToolTip, d: %D%
Sleep, 50
}
return
Re: Hold Key While Pressing Other Keys Without The Held Key Stopping?
That would probably work in most cases, but what I'm going for is probably a bit more complicated. s is it's own hotkey, but it's also a part of a combo hotkey. Thus, the goal is to seamlessly go from s to s & d, and then back to s, ad infinitum. It's not that s should be firing constantly, such as, even at the same time that s & d is firing. Rather, it's just that s should fire immediately after d is released, without also having to release and press s again. Is this possible?Rohwedder wrote:...
For example,
s::x
s & d:: y
Re: Hold Key While Pressing Other Keys Without The Held Key Stopping?
How about use s & d:: and then under the loop use getkeystate for d and write the actions below when keystate is up?
Also does anybody know why my script didn't work? I'm clueless.
It did for me btw. The values did keep incrementing so the settimer part worked. But the values didn't reset to 0 and the tooltip did not refresh.
Two while states is not good in general because of threading, evilc's thread was just an example.
https://autohotkey.com/docs/misc/Threads.htm
Also does anybody know why my script didn't work? I'm clueless.
It did for me btw. The values did keep incrementing so the settimer part worked. But the values didn't reset to 0 and the tooltip did not refresh.
Two while states is not good in general because of threading, evilc's thread was just an example.
https://autohotkey.com/docs/misc/Threads.htm
I am your average ahk newbie. Just.. a tat more cute.
Re: Hold Key While Pressing Other Keys Without The Held Key Stopping?
Did you edit your post? Your code works now, but it didn't earlier.Nwb wrote:How about use s & d:: and then under the loop use getkeystate for d and write the actions below when keystate is up?
Also does anybody know why my script didn't work? I'm clueless.
It did for me btw. The values did keep incrementing so the settimer part worked. But the values didn't reset to 0 and the tooltip did not refresh.
Two while states is not good in general because of threading, evilc's thread was just an example.
https://autohotkey.com/docs/misc/Threads.htm
Anyway, getkeystate is essentially what I've tried. It still stops when I release d though.
Code: Select all
s::
if(GetKeyState("d")) {
Send, y
}
else
Send x
Sleep 50
return
Re: Hold Key While Pressing Other Keys Without The Held Key Stopping?
Yes I did. And I thought that was the point (stops when you release d)??abcjme wrote:Did you edit your post? Your code works now, but it didn't earlier.Nwb wrote:How about use s & d:: and then under the loop use getkeystate for d and write the actions below when keystate is up?
Also does anybody know why my script didn't work? I'm clueless.
It did for me btw. The values did keep incrementing so the settimer part worked. But the values didn't reset to 0 and the tooltip did not refresh.
Two while states is not good in general because of threading, evilc's thread was just an example.
https://autohotkey.com/docs/misc/Threads.htm
Anyway, getkeystate is essentially what I've tried. It still stops when I release d though.
Code: Select all
s:: if(GetKeyState("d")) { Send, y } else Send x Sleep 50 return
Anyways did you try a & d:: like I said? Try doing that, if you need help I will make an example script
I am your average ahk newbie. Just.. a tat more cute.
Re: Hold Key While Pressing Other Keys Without The Held Key Stopping?
I'm not sure I understand what you mean. If it's not too much trouble, an example script would be great!Nwb wrote:Anyways did you try s & d:: like I said? Try doing that, if you need help I will make an example script
Re: Hold Key While Pressing Other Keys Without The Held Key Stopping?
Hallo,
you want s:: and s & d:: but only one should be active?
Then you do not need timers! Try:
but if you want s:: and d:: to be independent of each other, i.e. both should be able to be active at the same time:
you want s:: and s & d:: but only one should be active?
Then you do not need timers! Try:
Code: Select all
s::
While, GetKeyState("s","P")
{
ToolTip, s: %A_Index%
Sleep, 200
}
Return
~s & d::
While, GetKeyState("d","P")
{
ToolTip, d: %A_Index%
Sleep, 200
}
Return
Code: Select all
s := 0, d:= 0
Return
s::
HotKey, s, Off
SetTimer, STimer, 200
Return
s Up::
SetTimer, STimer, Off
HotKey, s, On
ToolTip
Return
STimer:
s++
ToolTip, s: %s% d: %d%
Return
d::
HotKey, d, Off
SetTimer, DTimer, 200
Return
d Up::
SetTimer, DTimer, Off
HotKey, d, On
ToolTip
Return
DTimer:
d++
ToolTip, s: %s% d: %d%
Return
Re: Hold Key While Pressing Other Keys Without The Held Key Stopping?
I had forgotten about the usefulness of the tilde. That did it, thanks!Rohwedder wrote:...
Who is online
Users browsing this forum: Google [Bot], Joey5 and 188 guests