Need help Maping Number Pad Key

Ask gaming related questions (AHK v1.1 and older)
Meyika
Posts: 2
Joined: 12 May 2014, 19:11

Need help Maping Number Pad Key

12 May 2014, 19:20

I use the following script to have the "3" key continuously run a macro as long as I am holding down the key.

$3::
While GetKeyState("3","p"){
Send 3
Sleep 90
}
return

It worked perfectly for what I need. However, now I would like to change the key to one of the keys on my number pad. However, simply inserting Numpad3 into the appropriate places doesn't seem to work. Can anyone please help me.

Thanks
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Need help Maping Number Pad Key

12 May 2014, 21:42

It seems to work for me. Make sure that Numlock is toggled on.

Code: Select all

$NumPad3::
While GetKeyState("NumPad3","p"){
	Send, {NumPad3}
	Sleep 90
}
return
Meyika
Posts: 2
Joined: 12 May 2014, 19:11

Re: Need help Maping Number Pad Key

13 May 2014, 09:10

kon wrote:It seems to work for me. Make sure that Numlock is toggled on.

Code: Select all

$NumPad3::
While GetKeyState("NumPad3","p"){
	Send, {NumPad3}
	Sleep 90
}
return
In my original script, I have: Send 3 and this seems to work. In the script you posted, you have: Send, {NumPad3} and I am wondering if the comma after "send" and the opening and closing braces around "NumPad3" in your script are necessary to make it work properly.
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Need help Maping Number Pad Key

13 May 2014, 10:44

Meyika wrote:In my original script, I have: Send 3 and this seems to work. In the script you posted, you have: Send, {NumPad3} and I am wondering if the comma after "send" and the opening and closing braces around "NumPad3" in your script are necessary to make it work properly.
Certain keys need to be enclosed in braces to be sent. See Key Names.
Try removing the braces. The literal text "NumPad3" will be sent instead of the key.
The comma is optional, it won't make a difference.
Girlgamer
Posts: 12
Joined: 03 Jun 2014, 14:52

Re: Need help Maping Number Pad Key

04 Jun 2014, 03:08

Since the numpad keys have essentially two states, one when the numlock key is on and one when it's off, it's important to remember that there are two separate names for each key. If the numlock is on the 5 key is {numpad5} but when the numlock is off the same key is named {numpadclear}. Also some games do not enable the numlock by default so if you really want the 5 key you might want to precede the 5 key with send, {numlock} and after the 5 key is sent do send, {numlock} again to make sure everything goes back to normal.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Need help Maping Number Pad Key

09 Jun 2014, 14:44

So just do something like this:

Code: Select all

numpadclear::
numpad5::
   While (GetKeyState("numpadclear","p") || GetKeyState("numpad5","p")){
       ; continuously runs while one of the keys is held
       Sleep 90
   }
   return
Also, you could probably use something like this for the while statement:

Code: Select all

While (GetKeyState(A_ThisHotKey,"p")){
A_ThisHotKey holds the name of the key that triggered the thread.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Need help Maping Number Pad Key

09 Jun 2014, 14:48

Another method of doing this is like so:

Code: Select all

key_down := 0

numpadclear::
numpad5::
   key_down := 1
   return

numpadclear up::
numpad5 up::
   key_down := 0
   return

heartbeat()
return

heartbeat(){
   global key_down

   Loop {
      if (key_down){
         ; this runs continuously while key held
      }
      sleep 90
   }
}
I think this method is more CPU efficient as you are doing less checks on the state of the key.
It is also useful in a wider variety of situations - for example to check if this key AND that key are held

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 51 guests