Using a sequence of keys as a hotkey, possible?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
JensHaglof
Posts: 81
Joined: 04 Jul 2017, 11:41

Using a sequence of keys as a hotkey, possible?

04 Jul 2017, 11:59

Hi!

I work at a warehouse where we distribute products. Prior to packaging, we put our products in plastic containers with barcodes on them. Every barcode starts with the letters ORP and then four numbers. For example ORP8954. I want to make a script that uses ORP as a hotkey. So when you scan a barcode, the script starts and outputs some keystrokes. Basically alt+k, alt+u and then enter four times. Something like this:

Code: Select all

ORP****::
Send !k
Send !u
Send {Enter}
Send {Enter}
Send {Enter}
Send {Enter}
Return
Is this possible?
/Jens
JensHaglof
Posts: 81
Joined: 04 Jul 2017, 11:41

Re: Using a sequence of keys as a hotkey, possible?

04 Jul 2017, 12:31

Hi. Thanks for the reply!
Would this work then?

Code: Select all

O::
input, command, L6

if command = RP****
Send !k
Send !u
Send {Enter}
Send {Enter}
Send {Enter}
Send {Enter}
Return
Rohwedder
Posts: 7645
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Using a sequence of keys as a hotkey, possible?

04 Jul 2017, 12:38

Hallo,
with a HotString:

Code: Select all

:*b0:ORP:: ;start with ORP
	Input, No,V L4 ;wait until Input text reaches the lenghth 4
	Send !k!u{Enter 4}
Return
JensHaglof
Posts: 81
Joined: 04 Jul 2017, 11:41

Re: Using a sequence of keys as a hotkey, possible?

04 Jul 2017, 13:12

Thanks Rohwedder! I will try that tomorrow at work!
JensHaglof
Posts: 81
Joined: 04 Jul 2017, 11:41

Re: Using a sequence of keys as a hotkey, possible?

19 Jul 2017, 16:20

It worked! Thank you so much!

I want to add another function.

If you press a key let's say [end] I want a different outcome. But I can't get it to work. What am I doing wrong?

:*b0:ORP::
Input, No,V L4
GetKeyState, state, End
if state = D
Send !p!k!u{Enter 4}
else
Send !k!u{Enter 4}
Return
Rohwedder
Posts: 7645
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Using a sequence of keys as a hotkey, possible?

19 Jul 2017, 23:47

Hallo,
I tried the script, it works! Probably your barcode tool has a problem with pressing "End".
Try:

Code: Select all

End::End := True
End Up::End := False
:*b0:ORP::
Input, No,V L4
If End
	Send !p!k!u{Enter 4}
else
	Send !k!u{Enter 4}
Return
JensHaglof
Posts: 81
Joined: 04 Jul 2017, 11:41

Re: Using a sequence of keys as a hotkey, possible?

20 Jul 2017, 04:33

Hi, thanks for the reply.
The script you suggested didn't work either. The error message I get in both scripts is "ELSE without matching IF"
JensHaglof
Posts: 81
Joined: 04 Jul 2017, 11:41

Re: Using a sequence of keys as a hotkey, possible?

23 Jul 2017, 10:14

No one?
Why is it saying "ELSE without matching IF"
Rohwedder
Posts: 7645
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Using a sequence of keys as a hotkey, possible?

23 Jul 2017, 23:41

Hallo,
my script does not have this error! The error must have happened when inserting my script into yours.
With a clean indentation https://autohotkey.com/docs/Tutorial.htm#s84 (use 1 tab per "level"!) and the line number specified in the error message, the error should be found.
JensHaglof
Posts: 81
Joined: 04 Jul 2017, 11:41

Re: Using a sequence of keys as a hotkey, possible?

16 Aug 2017, 12:00

Hi, I got it to work, I had to put { and } after the IF statement. Thank you!

Anyway, I have more problems. I want to be able to press NumpadSub and NumpadMult and store a value in a variable "sticker". This will then change what happen when you scan a barcode. Basically use Numpadsub and Numpadmult as a toggle switch. You tap it to change the value of the variable. This is what I've done so far:

Code: Select all

Input, SingleKey, L1, {NumpadSub}{NumpadMult}
If SingleKey = {NumpadSub}
{
sticker = false
}
If SingleKey = {NumpadMult}
{
sticker = true
}

:*b0:ORP::
Input, No,V L4
if sticker = true
{
send !p!k!u
}
else
{
send !k!u
}
Return
Anyone see the error in the code?
/Jens
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Using a sequence of keys as a hotkey, possible?

16 Aug 2017, 12:45

output from input doesn't include key names, or brackets. It contains the text produced by your typing, if I'm not mistaken.

Cheers.
JensHaglof
Posts: 81
Joined: 04 Jul 2017, 11:41

Re: Using a sequence of keys as a hotkey, possible?

16 Aug 2017, 13:16

Thanks for the reply. I've tried letters also.

If SingleKey = a

etc. It didn't work either.

/Jens
JensHaglof
Posts: 81
Joined: 04 Jul 2017, 11:41

Re: Using a sequence of keys as a hotkey, possible?

16 Aug 2017, 15:09

Yes I solved it!!

Code: Select all

Numpadmult::
sticker = true
Return

Numpadsub::
sticker = false
Return

:*b0:ORP::
Input, No,V L4
if sticker = true
{
send !p!k!u
}
else
{
send !k!u
}
Return
Didn't think of using hotkeys as inputs!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ccqcl, Descolada and 365 guests