can't get ControlSend to work

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Krypto888
Posts: 6
Joined: 26 Apr 2018, 07:01

can't get ControlSend to work

26 Apr 2018, 07:12

Hi guys,

I'm trying to get ControlSend to work so that keyboard keys are pressed when my .exe is not selected (not in foreground) but whatever I try, the script stops working if I click away from the exe

This is what I have:

Code: Select all

ControlSend,,my.exe

#Persistent
SetTimer, PressTheKey, 500
Return


#o::Pause ; 


IfWinActive,   my.exe

PressTheKey:

if (WinActive("ahk_exe my.exe")) 

{
	Send, {space down}
	Send, {F4 down}
	Sleep 10
	Send, {F4 up}
	Send, {z down}
	Sleep 10
	Send, {z up}
	
}
Return
If someone could help me it would be great, I tried reading about ControlSend and ControlClick but I find it hard to get it to work
RiRi Lopez

Re: can't get ControlSend to work

26 Apr 2018, 07:24

Krypto888 wrote:Hi guys,

I'm trying to get ControlSend to work so that keyboard keys are pressed when my .exe is not selected (not in foreground) but whatever I try, the script stops working if I click away from the exe

This is what I have:

Code: Select all

ControlSend,,my.exe

#Persistent
SetTimer, PressTheKey, 500
Return


#o::Pause ; 


IfWinActive,   my.exe

PressTheKey:

if (WinActive("ahk_exe my.exe")) 

{
	Send, {space down}
	Send, {F4 down}
	Sleep 10
	Send, {F4 up}
	Send, {z down}
	Sleep 10
	Send, {z up}
	
}
Return
If someone could help me it would be great, I tried reading about ControlSend and ControlClick but I find it hard to get it to work
my notes here

Code: Select all

ControlSend,,my.exe ; you placed this in the auto execute section, and it does nothing 

#Persistent
SetTimer, PressTheKey, 500
Return


#o::Pause ; 


IfWinActive,   my.exe  ; nothing calls this 

PressTheKey:

if (WinActive("ahk_exe my.exe")) 

{
	Send, {space down}
	Send, {F4 down}
	Sleep 10
	Send, {F4 up}
	Send, {z down}
	Sleep 10
	Send, {z up}
	
}
Return
I think you need to tell us more what the goal is, i am confused.
Krypto888
Posts: 6
Joined: 26 Apr 2018, 07:01

Re: can't get ControlSend to work

26 Apr 2018, 08:57

RiRi Lopez wrote:
I think you need to tell us more what the goal is, i am confused.
Hi, sorry!

I need a very simple thing, my goal is to be able to hold 'space' all the time, while pressing F4 every second or so as well as pressing Z every second or so. I also added 'win+o' to pause and unpause it. This has to work only on a specified .exe program, so that I can still use my PC while it's working, but also so that the script works on that .exe when the window is not active. So let's say I want to run the script to press the 3 keys on my.exe while still being able to do other things on the computer. As for now, everything works for me except when I want to do other things on my computer, then the script stops working on the .exe
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: can't get ControlSend to work

28 Apr 2018, 08:22

Code: Select all

#Persistent
SetTimer, PressTheKey, 500
Return

target := "ahk_exe Wow.exe"

#o::Pause

PressTheKey:
{
	ControlSend, , {Space Down}, % target
	ControlSend, , {F4 Down}, % target
	Sleep, 10
	ControlSend, , {F4 Up}, % target
	ControlSend, , {z Down}, % target
	Sleep, 10
	ControlSend, , {z Up}, % target
return
}
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: can't get ControlSend to work

29 Apr 2018, 12:40

Hi.
ControlSend [, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText]
As description for Control-parameter, help-file says: "If this parameter is blank or omitted, the target window's topmost control will be used."
Another thing is, that it seems, that you have used Window-Title called "my.exe" as key-parameter instead for WinTitle-parameter.
Einfach nur ein toller Typ. :mrgreen:
Krypto888
Posts: 6
Joined: 26 Apr 2018, 07:01

Re: can't get ControlSend to work

02 May 2018, 06:20

swagfag wrote:

Code: Select all

#Persistent
SetTimer, PressTheKey, 500
Return

target := "ahk_exe Wow.exe"

#o::Pause

PressTheKey:
{
	ControlSend, , {Space Down}, % target
	ControlSend, , {F4 Down}, % target
	Sleep, 10
	ControlSend, , {F4 Up}, % target
	ControlSend, , {z Down}, % target
	Sleep, 10
	ControlSend, , {z Up}, % target
return
}

This is not working at all, I changed the wow.exe to my exe and nothing is happening
Krypto888
Posts: 6
Joined: 26 Apr 2018, 07:01

Re: can't get ControlSend to work

02 May 2018, 06:21

divanebaba wrote:Hi.
ControlSend [, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText]
As description for Control-parameter, help-file says: "If this parameter is blank or omitted, the target window's topmost control will be used."
Another thing is, that it seems, that you have used Window-Title called "my.exe" as key-parameter instead for WinTitle-parameter.

Sorry, I have no idea what any of that means
Hildagard K

Re: can't get ControlSend to work

02 May 2018, 06:56

Krypto888 wrote:
divanebaba wrote:Hi.
ControlSend [, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText]
As description for Control-parameter, help-file says: "If this parameter is blank or omitted, the target window's topmost control will be used."
Another thing is, that it seems, that you have used Window-Title called "my.exe" as key-parameter instead for WinTitle-parameter.

Sorry, I have no idea what any of that means
"If this parameter is blank or omitted, the target window's topmost control will be used"

If you do controlsend, edit1, b, WinTitle it will send to edit1, if you leave out edit1 it will send to the targets top most control

"you have used Window-Title called "my.exe" as key-parameter instead for WinTitle-parameter."

Read up on WinTitle
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: can't get ControlSend to work

02 May 2018, 10:37

Run as admin. Try increasing the delay between send events
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: can't get ControlSend to work

02 May 2018, 18:11

Hi.
Help-file says, concerning for control-parameter:"If this parameter is ahk_parent, the keystrokes will be sent directly to the target window instead of one of its controls"
So try to add ahk_parent as parameter for all your ControlSend-commands, like below:

Code: Select all

ControlSend, ahk_parent, {Space Down}, % target
...
As I don't know anything about your my.exe I can only give support like a bad doctor, giving you random pills to try. :lol: :lol:
Einfach nur ein toller Typ. :mrgreen:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: hedehede81 and 281 guests