NumPad x2

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
zoverlvx
Posts: 55
Joined: 30 Dec 2015, 21:41

NumPad x2

06 May 2016, 20:55

I'm using NumPad numerals to type numbers that help me navigate through IBM windows at a faster rate.
Is there any way to specify a NumPad numeral x2 in order to send commands/whatever I want?


This is what I have and it works for what it's intended

Code: Select all

NumPad1::
send, 2
send, {enter}
sleep, 200
send, 18
send, {enter}
return
however I'd like it closer to this

Code: Select all

NumPad1 & NumPad1::  ;have also tried &&
send, 2
send, {enter}
sleep, 200
send, 18
send, {enter}
return
so that when I type NumPad1 twice it'll follow the command.

I've also tried

Code: Select all

{NumPad1 2}::
send, 2
send, {enter}
sleep, 200
send, 18
send, {enter}
return
Neither works. I know it's got to be a simple solution, but everything that I know so far isn't fixing it.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: NumPad x2

06 May 2016, 21:11

Code: Select all

Numpad1::
If (A_PriorKey="Numpad1")
{
MsgBox Hi, you've pressed %A_ThisHotkey% twice!
}
return
Close to what you're looking for?

Edit: Better code by Xtra down below; I didn't realize A_PriorHotkey was a thing.
Last edited by Exaskryz on 10 May 2016, 18:28, edited 1 time in total.
zoverlvx
Posts: 55
Joined: 30 Dec 2015, 21:41

Re: NumPad x2

10 May 2016, 16:58

Exaskryz wrote:

Code: Select all

Numpad1::
If (A_PriorKey="Numpad1")
{
MsgBox Hi, you've pressed %A_ThisHotkey% twice!
}
return
Close to what you're looking for?

No, my problem is with the hotkey itself. I want it to send something when I type 22, but only when those 2's are from the number pad.
I've already tried a couple combinations to make it work. Below is what I've tried:

Code: Select all

NumPad22:: ;then send whatever I want

Code: Select all

NumPad2 & NumPad2::

Code: Select all

NumPad2 + NumPad2::

Code: Select all

{NumPad2 2}::
I have no idea what it needs as a hotkey configuration to get this program to work.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: NumPad x2

10 May 2016, 17:02

Well, if you take my code and change it to Numpad2 instead of Numpad1 (in both parts), it should be working. Do you not get a MsgBox to appear when you press 22 in a row, using the numpad?
User avatar
kwstas13
Posts: 43
Joined: 19 Mar 2016, 06:26

Re: NumPad x2

10 May 2016, 18:10

Code: Select all

Numpad2:= 0

$Numpad2::
if ((A_TickCount - Numpad2) <= 250)
	Send 2,{enter}
Sleep 200
Send 18,{enter}
else
	Send 2
Numpad2:= A_TickCount
Return 
You can try this code has not been tested
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: NumPad x2

10 May 2016, 18:19

Code: Select all

~Numpad2::
    if (A_PriorHotkey = A_ThisHotkey) && (A_TimeSincePriorHotkey <= 400)
	    Send, This is my message when numpad2 is pressed 2x within 400ms!
return
?
zoverlvx
Posts: 55
Joined: 30 Dec 2015, 21:41

Re: NumPad x2

10 May 2016, 18:31

Code: Select all

Numpad2:= 0
 
$Numpad2::
if ((A_TickCount - Numpad2) <= 250)
	Send 2,{enter}
Sleep 200
Send 18,{enter}
else
	Send 2
Numpad2:= A_TickCount
Return 
Error: Else with no matching IF
User avatar
kwstas13
Posts: 43
Joined: 19 Mar 2016, 06:26

Re: NumPad x2

10 May 2016, 18:37

zoverlvx wrote:

Code: Select all

Numpad2:= 0
 
$Numpad2::
if ((A_TickCount - Numpad2) <= 250)
	Send 2,{enter}
Sleep 200
Send 18,{enter}
else
	Send 2
Numpad2:= A_TickCount
Return 
Error: Else with no matching IF

Code: Select all

Numpad2:= 0
 
$Numpad2::
if ((A_TickCount - Numpad2) <= 250)
{
	Send 2,{enter}
Sleep 200
Send 18,{enter}
}
else
{
	Send 2
}
Numpad2:= A_TickCount
Return 
zoverlvx
Posts: 55
Joined: 30 Dec 2015, 21:41

Re: NumPad x2

19 May 2016, 18:25

Nothing really seems to be working for this.

What's a "best practice" for telling the code to run a certain way if and only if such-and-such a window is running?
It won't work if I only invoke the name of the program (even though it's on the desktop). Do I need to use the C:/ path in the script to get it to run?
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: NumPad x2

19 May 2016, 21:03

Either you can use for a hotkey #IfWinActive, or you can use If WinActive() within the hotkey. (The second part is two different links).

You likely don't need the C:/ path in the script.

I think we'll need a bit more information and what code it is you have running down (is it kwstas13's latest code?)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Descolada, garry, Google [Bot], Joey5 and 311 guests