[Beginner] Script not working properly, please help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MPeti1
Posts: 6
Joined: 16 Feb 2018, 12:45

[Beginner] Script not working properly, please help

16 Feb 2018, 13:06

Hi!
I've written a script with the purpose to send F5 (update) to Process Hacker's window, but i have problems with it.
Firstly, I've made a toggle in it, but it's not fully working. I can start the script, but i can't stop it. I know it's running because i can see it in the debug window.
I think it's because it can't detect the F4 press while it's in the while loop, but I don't know what to do with it.
Secondly, it seems the F5 key is not sent properly, or PH can't receive it this way, because nothing happens. Process Hacker runs in admin mode and i've ran the script in admin mode.

Can you help me please?
Here is the script:

Code: Select all

enabled := 0
F4::
enabled := !enabled

while(enabled){
	ControlSend, ahk_exe ProcessHacker.exe, F5
}
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: [Beginner] Script not working properly, please help

16 Feb 2018, 16:22

I never like using a hotkey to interrupt the process that was initiated by that hotkey and is ongoing. Just have the while loop in the auto-execute part of your script and use F4 to only set the toggle like below. Also, use { } around F5. No guarantee that it will work, however, since ControlSend doesn't work with all applications or windows.

Code: Select all

enabled := 0
while(enabled){
	ControlSend, ahk_exe ProcessHacker.exe, {F5}
}
return

F4::enabled := !enabled
MPeti1
Posts: 6
Joined: 16 Feb 2018, 12:45

Re: [Beginner] Script not working properly, please help

17 Feb 2018, 05:45

Thanks for the reply.
But then F4 only toggles, and the while loop will not start :/
You said you think it's not a good solution, i agree :D but how would you do that? I mean, toggling a key's continuous sending to a window.
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: [Beginner] Script not working properly, please help

17 Feb 2018, 07:02

This change should do it:

Code: Select all

enabled := 0
loop
	while(enabled)
		ControlSend, ahk_exe ProcessHacker.exe, {F5}
return

F4::enabled := !enabled
MPeti1
Posts: 6
Joined: 16 Feb 2018, 12:45

Re: [Beginner] Script not working properly, please help

17 Feb 2018, 16:47

This way i can toggle it, but it will still drain the cpu. (not much, about 8% avg, but it bothers me). On the other hand, the target window will not get the key press for some reason. I tried some other methods to send key presses to the PH window, but Winspector Spy fails to detect WM_COMMAND messages
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: [Beginner] Script not working properly, please help

17 Feb 2018, 16:59

As I said in my first post in this thread, not all windows will respond to ControlSend. Or you may have to send it to a specific control in that window. Just try several things and see what works, if anything.

As far as CPU time goes, this should help that. It will still probably be high CPU while you're sending {F5} with no pause in between, but not while it's just waiting for you to enable it.

Code: Select all

enabled := 0
loop
{
	while(enabled)
		ControlSend, ahk_exe ProcessHacker.exe, {F5}
	Sleep, 400
}
return

F4::enabled := !enabled
MPeti1
Posts: 6
Joined: 16 Feb 2018, 12:45

Re: [Beginner] Script not working properly, please help

18 Feb 2018, 08:36

Thanks, this is perfect :D Now i just need to find out how to send F5 to the window
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: [Beginner] Script not working properly, please help

18 Feb 2018, 20:09

Take a look at ControlSend
The command parameters:
ControlSend, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText

This:

Code: Select all

ControlSend, ahk_exe ProcessHacker.exe, {F5}
Should be:

Code: Select all

ControlSend,, {F5},  ahk_exe ProcessHacker.exe
or:

Code: Select all

ControlSend, ahk_parent, {F5}, ahk_exe ProcessHacker.exe
HTH
MPeti1
Posts: 6
Joined: 16 Feb 2018, 12:45

Re: [Beginner] Script not working properly, please help

19 Feb 2018, 18:17

How i wasn't able to notice i put the parameters in a wrong order... :DDD Thanks
But this way PH still fails to accept the input :/

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 207 guests