Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Ignore certain physical keypresses while function is holding a key to make sure the hold is uninterupted by the other keys



  • Please log in to reply
3 replies to this topic
Mln1
  • Members
  • 6 posts
  • Last active: Mar 30 2018 02:05 PM
  • Joined: 15 Jun 2013
yo, this is simplified snippet situation of my problem for a game where you move by W / A / S / D keys
 
the function checks for the variable "something" and once that something is 1 (which is manually set to 1 in this script right away just for testing purposes), the function will start holding "e". i need that "e" to be a continuous hold that doesnt get even slightly interupted by pressing any of WASD while its running, or by holding any of WASD prior to the function starting its "e" holding operation.  obviously i dont expect the wasd to actually work in the game for that duration of course,  but other keys other than WASD need to work normally (meaning it doesnt matter if those can interfere with the e hold, but ahk needs to be able to process them while this function is going because they will be stopping the function later but thats not important now)
 
it can be tested by having the function run and have it spam the E in a textfile and then pressing other keys to see how they interfere with the E spam but i need a clean uninterupted E hold while the function is running, it needs to somehow ignore/disable any of the WASD prior to starting the E hold and keep ignoring while its running (while something == 1). 
 
i tried some ghetto workarounds like sending each of {WASD up} first or using Hotkey command to make the letters call an empty function to block them or call this function itself or even blockinput (which is not an option anyway) but nothing worked, it either wont let the function do its thing at all or will spam letters inbetween the e or pause the hold momentarily.
 
i guess this has more to do with the physical press than what i do virtually inside ahk but either way i lack advanced knowledge of ahk and eventho i tried looking for something relevant in the manual+google, i just couldnt find a hint of what to study to achieve this, so any tips of what to look into or even working snippet examples are appreciated. thanks
 
 
SetTimer, testFunction, 10
something = 1
return


testFunction:
if (something == 1)
{
send {e down}
}
return


Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012
✓  Best Answer

Try this:

SetTimer, testFunction, 10
something = 1
return

F1::something:=!something ; changes the value between 1 and 0
 
testFunction:
if (something=1)
{
send {e down}
}
else ; something != 1
{
send {e up}
}
return
 
#If something=1
w::return
a::return
s::return
d::return

#If directive



Mln1
  • Members
  • 6 posts
  • Last active: Mar 30 2018 02:05 PM
  • Joined: 15 Jun 2013

wooot so thats how that #if works, i was already using it for #if winactive but never realized that it could be applied to hotkeys too and not error out on duplicate hotkey when i remap the same hotkeys outside of it later in the script. thats cool, now i assume if i want to use it for your example but iam already inside an #if winactive(...) zone, it cannot be nested but instead will overrule the previous winactive so i guess i need to redeclare #if winactive(...) right after your snippet to keep the code specific to my application.

 

either way, while messing around with your suggestion it led me to realize that the problem was partially somewhere else, in the game setting itself, so now after all i got both cleaner code and learnt something new, thanks!<3

 

(i really need to sit down with the whole ahk manual page by page one day and just mess around, so much untapped power)



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

For your question on combining conditions, you'd do something like this: #If (something=1) && WinActive("My Program").

 

And you're right, there is a lot that AHK can do.