Need help with solving two problem in binding script Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Boopyboop
Posts: 5
Joined: 21 Feb 2018, 08:12

Need help with solving two problem in binding script

21 Feb 2018, 08:56

Hello! In advance I apologize for my bad English.
I have this code:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



I'm new to ahk, I tried to figure it out myself, but in the end I ran into two problems, in which I need help:
1)If I move the code from Suspend hotkeys section above Core Code section, then binding on W key stops working. How I can fix it without move Suspend hotkeys section below Core Code section?
2)Code in the Key Remapper for Doc section doesn't working, why and how solve this problem? The code in Key Remapper for Notepad++ section is working fine (As I understand it, the problem is that CurID_2 and WinID_2 doesn't get values, but I don't understand why)

I'm more than sure that I make very stupid errors in the code, but I can't find them very long time, please help.
Thanks for reading.
User avatar
evilC
Posts: 4180
Joined: 27 Feb 2014, 12:30

Re: Need help with solving two problem in binding script

21 Feb 2018, 11:36

You are using #if wrong.

Code: [Select all] [Download] GeSHi © Codebox Plus

#If WinActive(WatchProg_2)
WinGet, WinID_2, ID, % WatchProg_2
MouseGetPos,,, CurID_2,, 1


#if is purely to turn on/off hotkeys due to context.
Code inside an #if block does not run when the condition is true, it just affects whether a hotkey declaration inside the #if block is active or not.
Boopyboop
Posts: 5
Joined: 21 Feb 2018, 08:12

Re: Need help with solving two problem in binding script

21 Feb 2018, 15:25

evilC wrote:You are using #if wrong.

Code: [Select all] [Download] GeSHi © Codebox Plus

#If WinActive(WatchProg_2)
WinGet, WinID_2, ID, % WatchProg_2
MouseGetPos,,, CurID_2,, 1


#if is purely to turn on/off hotkeys due to context.
Code inside an #if block does not run when the condition is true, it just affects whether a hotkey declaration inside the #if block is active or not.


Hello again. I tried fix my code,

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Problem №2 is solved now, thanks for help. But can you explain about Problem №1?
Boopyboop
Posts: 5
Joined: 21 Feb 2018, 08:12

Re: Need help with solving two problem in binding script

22 Feb 2018, 08:20

evilC wrote:You are still using #if for random stuff I have no clue why you are using it.

Why did you use #if for these bits of code?

Code: [Select all] [Download] GeSHi © Codebox Plus

#If
GroupAdd, WatchProg_1, ahk_exe Notepad++.exe
GroupAdd, WatchProg_2, ahk_exe WINWORD.exe




Isn't easy for me understand this, sorry for my stupidity. First If is unnecessary, but without second If Scrollllock will stop working anywhere except programs WatchProg_1 and WatchProg_2

P.S. I have new question: Any binds stop working when active window of TaskManager, Don't Starve Together and Dark Souls 3, how I can fix it?
User avatar
evilC
Posts: 4180
Joined: 27 Feb 2014, 12:30

Re: Need help with solving two problem in binding script

22 Feb 2018, 08:58

If games don't see the input AHK sends, then you probably need to run the script as admin.

The ONLY thing inside an #if statement should be hotkeys.

Code: [Select all] [Download] GeSHi © Codebox Plus

#if
GroupAdd, WatchProg_1, ahk_exe Notepad++.exe

This is totally not valid.
1) #if on it's own CLOSES an #if block. This line is before any other #if statements, so makes no sense.
2) If it IS meant to be "inside" an #if block, you cannot just put code in an #if block like that.

CORRECT usages of #if

Turning on/off hotkeys depending on value of a variable:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Turning on/off hotkeys depending on active window:

Code: [Select all] [Download] GeSHi © Codebox Plus

#ifWinActive, blah
; <-- YOU CANNOT PUT NORMAL CODE HERE!!
F12::
msgbox
return
#ifWinActive ; close the #if block
Boopyboop
Posts: 5
Joined: 21 Feb 2018, 08:12

Re: Need help with solving two problem in binding script

22 Feb 2018, 18:00

evilC wrote:If games don't see the input AHK sends, then you probably need to run the script as admin.

The ONLY thing inside an #if statement should be hotkeys.

Code: [Select all] [Download] GeSHi © Codebox Plus

#if
GroupAdd, WatchProg_1, ahk_exe Notepad++.exe

This is totally not valid.
1) #if on it's own CLOSES an #if block. This line is before any other #if statements, so makes no sense.
2) If it IS meant to be "inside" an #if block, you cannot just put code in an #if block like that.

CORRECT usages of #if

Turning on/off hotkeys depending on value of a variable:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Turning on/off hotkeys depending on active window:

Code: [Select all] [Download] GeSHi © Codebox Plus

#ifWinActive, blah
; <-- YOU CANNOT PUT NORMAL CODE HERE!!
F12::
msgbox
return
#ifWinActive ; close the #if block


Now is this correct code or I still doing something wrong?

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



P.S. Run the script as admin is solved my problem, thanks.
User avatar
evilC
Posts: 4180
Joined: 27 Feb 2014, 12:30

Re: Need help with solving two problem in binding script  Topic is solved

22 Feb 2018, 19:32

Looks a lot better.
About the only issue I see is that this code is a little risky:

Code: [Select all] [Download] GeSHi © Codebox Plus

с::
If (CurID = WinID_1)
{
Send {r down}
KeyWait, w ; <--- pausing mid-hotkey like this *can* cause problems
Send {r up}
}
Return

Be aware that this technique (waiting in a hotkey indefinitely) causes issues if you try to do it with more than one hotkey.
Splitting the code into a press hotkey and a release hotkey is better:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Boopyboop
Posts: 5
Joined: 21 Feb 2018, 08:12

Re: Need help with solving two problem in binding script

23 Feb 2018, 04:29

evilC wrote:Looks a lot better.
About the only issue I see is that this code is a little risky:

Code: [Select all] [Download] GeSHi © Codebox Plus

с::
If (CurID = WinID_1)
{
Send {r down}
KeyWait, w ; <--- pausing mid-hotkey like this *can* cause problems
Send {r up}
}
Return

Be aware that this technique (waiting in a hotkey indefinitely) causes issues if you try to do it with more than one hotkey.
Splitting the code into a press hotkey and a release hotkey is better:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Thanks for help with key holding, this much help me. And thanks for taking the time.

Return to “Ask For Help”

Who is online

Users browsing this forum: bxdobs, colt, DyaTactic, evilC, rscott and 40 guests