Why are the hotkeys not working?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

Why are the hotkeys not working?

Post by vsub » 20 Jun 2021, 07:00

Code: Select all

#Persistent
#SingleInstance Force
OnExit, UnHook

hHookMouse := DllCall("SetWindowsHookEx", "int", 14, "Uint", RegisterCallback("Mouse", "Fast"), "Uint", 0, "Uint", 0)

#IfWinNotActive,ahk_exe BH3.exe
~WheelUp::
~Wheeldown::
msgbox,% my
If MY < 1050
Return
IfInString,A_ThisHotKey,Up
Send,{Volume_Up}
Else
Send,{Volume_Down}
Return

UnHook:
DllCall("UnhookWindowsHookEx", "Uint", hHookMouse)
ExitApp

Mouse()
{
global my
MouseGetPoS,MX,MY
If (( MX = "1927" ) & ( MY = "1087" ))
{
Send ^!{Tab}
MouseMove,1926,1086
}
}

Esc::
ExitApp

Also why is the Mouse function keeps taking the mouse position even if I add something like a message box or WinWaitActive and then WinWaitClose after the Send command)
Is there is a way to "pause" the function until the window is closed

User avatar
boiler
Posts: 16705
Joined: 21 Dec 2014, 02:44

Re: Why are the hotkeys not working?

Post by boiler » 20 Jun 2021, 08:42

When you say the hotkeys are not working, do you mean they are not doing what you expect or that they are not even firing? Does the Esc key not even exit the script? Are you trying to use the hotkeys when the BH3.exe app’s window is the active window?

just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Why are the hotkeys not working?

Post by just me » 20 Jun 2021, 08:55

Calling the CallNextHookEx function to chain to the next hook procedure is optional, but it is highly recommended; otherwise, other applications that have installed hooks will not receive hook notifications and may behave incorrectly as a result. You should call CallNextHookEx unless you absolutely need to prevent the notification from being seen by other applications.

Source: SetWindowsHookEx()
?

vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

Re: Why are the hotkeys not working?

Post by vsub » 20 Jun 2021, 09:08

boiler wrote:
20 Jun 2021, 08:42
When you say the hotkeys are not working, do you mean they are not doing what you expect or that they are not even firing? Does the Esc key not even exit the script? Are you trying to use the hotkeys when the BH3.exe app’s window is the active window?
The WheelUp and Wheeldow hotkeys are doing literally nothing,even the msgbox don't appear and the BH3.exe is not the active window(it's not even running)
They also don't work even if I remove the IfWinNotActive condition
The Esc key is working but those two are not no matter where I move the code
If I remove the hHookMouse,then they start to work

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Why are the hotkeys not working?

Post by swagfag » 20 Jun 2021, 09:30

i suspect windows is unloading ur hook after a while, which also breaks other hotkeys implemented using a mousehook

this means theres a problem with the way ur hook proc is coded. it takes too long to run, exceeding the specified timeout. or maybe it exceeds some internal windows concurrent hook instance count per process. it doesnt seem safe to call MouseMove from the hook proc. i can see how it could cause hook to trigger recursively. better unhook, move, then rehook instead

vsub
Posts: 541
Joined: 29 Sep 2015, 03:39

Re: Why are the hotkeys not working?

Post by vsub » 20 Jun 2021, 09:54

swagfag wrote:
20 Jun 2021, 09:30
i suspect windows is unloading ur hook after a while, which also breaks other hotkeys implemented using a mousehook

this means theres a problem with the way ur hook proc is coded. it takes too long to run, exceeding the specified timeout. or maybe it exceeds some internal windows concurrent hook instance count per process. it doesnt seem safe to call MouseMove from the hook proc. i can see how it could cause hook to trigger recursively. better unhook, move, then rehook instead
I just found that code while I was looking for a way to get the mouse position only while moving it(not constantly with a loop or settimer)and to work globally,not just over an ahk gui window
I don't know how good it is(don't even know what some of it mean)

just me
Posts: 9406
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Why are the hotkeys not working?

Post by just me » 20 Jun 2021, 10:35

Code: Select all

~WheelUp::
~Wheeldown::
The associated WM_MOUSEWHEEL messages might be forwarded to your low-level mouse hook proc and swallowed before they are identified as hotkeys by AHK. That's why I recommended to try to call CallNextHookEx().
LowLevelMouseProc wrote:wParam [in]
Type: WPARAM

The identifier of the mouse message. This parameter can be one of the following messages: WM_LBUTTONDOWN, WM_LBUTTONUP, WM_MOUSEMOVE, WM_MOUSEWHEEL, WM_MOUSEHWHEEL, WM_RBUTTONDOWN, or WM_RBUTTONUP.

Post Reply

Return to “Ask for Help (v1)”