sending ctrl, alt, and shift combos

Ask gaming related questions (AHK v1.1 and older)
dluxx00
Posts: 6
Joined: 21 Oct 2015, 09:59

sending ctrl, alt, and shift combos

11 Nov 2015, 06:03

I am having trouble with a script that i'm using to send keystrokes to World of Warcraft such as ctrl+1, shift+2, alt+3, and it does not want to send them. I tried using the sendplay command and I tried:

Code: Select all

send {^1}
I also tried:

Code: Select all

send {^ Down}
send {1}
send {^ Up}
Neither method works. If you need to see the full script I will include it.

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

$^+w::
KeyWait w
send {w Down}
return

$^+o::
SetTimer, wsAway, 300000

wsAway:
KeyWait w
send {w Down}
sleep 100
send {w Up}
sleep 100
KeyWait s
send {s Down}
sleep 266
send {s Up}
return
 
$^+p::SetTimer, wsAway, Off

f2::
sendplay {+ Down}
sendplay {n}
sendplay {+ Up}
SetTimer, wsRD1, 5

wsRD1:
sendplay {+ Down}
sendplay {.}
sendplay {+ Up}
return

f3::SetTimer, wsRD1, Off

c::
send {^ Down}
send {1}
send {^ up}
return

Pause::
Suspend
Pause,,1
return
There must be another method to send these keystrokes that I haven't found. Thanks for any help you can provide.
dluxx00
Posts: 6
Joined: 21 Oct 2015, 09:59

Re: sending ctrl, alt, and shift combos

11 Nov 2015, 10:31

that doesn't solve the issue and I've been using this syntax with no issues otherwise (without ctrl, alt, shift combos)
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: sending ctrl, alt, and shift combos

11 Nov 2015, 11:06

dluxx00 wrote:that doesn't solve the issue and I've been using this syntax with no issues otherwise (without ctrl, alt, shift combos)
That doesn't mean your original syntax wasn't wrong.

Open a text editor, paste in this text and run:

Code: Select all

F11::
	Send {^a}
	return

F12::
	Send ^{a}
	return
F11 does not select all, F12 does.
Therefore, the ^ MUST be outside the brackets.

If it still isn't working, there is another issue.
Might I suggest that this is also incorrect syntax:

Code: Select all

send {^ Down}
You cannot send a modifier (especially a common variant one) as a key.
You can only send a modifier key on it's own as one of the L/R variants. ie you cannot send "Control down", you can only send "Left Control down"
I suspect you may want:

Code: Select all

Send {LCtrl down}
dluxx00
Posts: 6
Joined: 21 Oct 2015, 09:59

Re: sending ctrl, alt, and shift combos

11 Nov 2015, 15:15

Ok i see the problem. It works now. Thanks for your help.
CoolBroVince
Posts: 7
Joined: 11 Nov 2015, 15:50

Re: sending ctrl, alt, and shift combos

11 Nov 2015, 16:13

Hello,
I have a similar problem with using the ctrl key. I want to select a unit (It's hotkey in the game is .) then assign it to control group 0. Autohotkeys is selecting the unit, but the control group is not working. I looked at the previous posts in this topic and this is what I have so far..

Code: Select all

;Select Idle villager, assign it to control-0
/::
Send .
Send {LCtrl down}
Send 0
Send {LCtrl up}
CoolBroVince
Posts: 7
Joined: 11 Nov 2015, 15:50

Re: sending ctrl, alt, and shift combos

11 Nov 2015, 20:26

evilC wrote:some games need a delay, and sometimes don't like too short a gap between keypresses
try adding SetKeyDelay, 0, 50 to the start of the script
Then try Send ^{0}
If it matters, the game I am trying to make it work for is Age of Empires 2: HD Edition. Thanks evilC for your efforts. I tried this and it didn't work:

Code: Select all

/::
SetKeyDelay, 0, 50
Send .
sleep 40
Send ^{0}
return
It is definitely selecting the villager because I hear the villager sound, but then the ctrl command to put it in control group 0 is still not working.
CoolBroVince
Posts: 7
Joined: 11 Nov 2015, 15:50

Re: sending ctrl, alt, and shift combos

13 Nov 2015, 21:18

evilC wrote:try this:

Code: Select all

F12::LCtrl
Then HOLD F12 and press the 0 key.
Does it add the selection to group 0?

If so, then the game is "seeing" AHK press the CTRL key.
If not, it isn't.

Unfortunately it looks like the game is not seeing it. It is not working when I hold F12 and press 0. Any other tries? I have been scouring some pages and I can't think of any other tries.
CoolBroVince
Posts: 7
Joined: 11 Nov 2015, 15:50

Re: sending ctrl, alt, and shift combos

14 Nov 2015, 02:48

I think I found a solution to my problem!

https://autohotkey.com/board/topic/1117 ... he-basics/

The problem with ctrl was that I needed to let it sleep during the ctrl so the game could register it.

Code: Select all

;Select 5 Idle villagers
/::

Send .
sleep 40
Send {LCtrl Down}sleep 15 
send 0 {LCtrl Up}
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: sending ctrl, alt, and shift combos

14 Nov 2015, 06:46

Hmm, that's why I had you hold F12 - to eliminate key delay as an issue. The F12::LCtrl syntax should mean that the up and down events are synced.

You may also wish to look up SetKeyDelay, which should let you insert sleeps after each keypress without having to use a sleep command each time.

Glad you found a solution.
CoolBroVince
Posts: 7
Joined: 11 Nov 2015, 15:50

Re: sending ctrl, alt, and shift combos

14 Nov 2015, 13:17

Yeah, I think I need to use SetKeyDelay somehow because I'm having another problem -

Code: Select all

;Select 5 Idle villagers
/::
 
Send .
sleep 40
Send {LCtrl Down}sleep 15 
send 0 {LCtrl Up}
this code is only sort of working because sometimes when I hold down the hotkey to run the script "/" the villager will try to build a stable for a split second. The hotkey to build a stable is "se" , so I'm thinking the sleep command is messing something up. It's very weird. I also had a villager miraculously get into Ctrl group 5, so it must be reading the "5" in sleep 15 in some instances
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: sending ctrl, alt, and shift combos

14 Nov 2015, 14:27

Code: Select all

Send {LCtrl Down}sleep 15
the sleep command is messing something up
What you have there isn't a sleep command. This is only one send command on that line, which holds downLCtrl and then sends the letters s, l, e, e, p, then a SpaceChar followed by the digits 1 and 5.

Try this instead: (two commands written on two separate lines)

Code: Select all

Send {LCtrl Down}
sleep 15
CoolBroVince
Posts: 7
Joined: 11 Nov 2015, 15:50

Re: sending ctrl, alt, and shift combos

14 Nov 2015, 21:06

wolf_II wrote:

Code: Select all

Send {LCtrl Down}sleep 15
the sleep command is messing something up
What you have there isn't a sleep command. This is only one send command on that line, which holds downLCtrl and then sends the letters s, l, e, e, p, then a SpaceChar followed by the digits 1 and 5.

Try this instead: (two commands written on two separate lines)

Code: Select all

Send {LCtrl Down}
sleep 15
Thanks for the input, I tried this:

Code: Select all

;Select 2 Idle villagers
/::
Send .
sleep 40
Send {LCtrl Down}
sleep 30
send 0{LCtrl Up}
sleep 40
send ..
send {Shift Down}
sleep 30
send 0{shift Up}
sleep 40
Send {LCtrl Down}
sleep 30
send 0{LCtrl Up}
Basically, "." finds an idle villager, "ctrl+0" should put it in control group 0, then go to the next villager ".." , then add it to control group zero "shift+0" then "ctrl+0"
CoolBroVince
Posts: 7
Joined: 11 Nov 2015, 15:50

Re: sending ctrl, alt, and shift combos

14 Nov 2015, 21:09

And thank you for helping me through the easy mistakes - I just started using AHK, but you probably already figured that out. :)

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 80 guests