#if interferes with normal (outside) hotkeys [maybe a bug]

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
aaurteo
Posts: 9
Joined: 28 Dec 2015, 01:42

#if interferes with normal (outside) hotkeys [maybe a bug]

25 Jan 2016, 19:29

Hi all,

Here is the sample code. You are supposed to see "Hello World!" when the hotkey is triggered. But you will never see "Hello World!" although the "Shift & WheelDown" is inside #if or #ifWinActive, or Notepad is not active.

I test with an alphabet letter instead of WheelDown/Up (like ^+A and +A), and it works well as expected. So it's a mouse wheel's problem. Maybe a bug? Is there a way to solve this except changing Shift & WheelDown:: to +WheelDown:: ?

Code: Select all

^+WheelDown::
	MsgBox, % "Hello World!"
Return

^+WheelUp::
	MsgBox, % "I'm still working."
Return

;#if WinActive("ahk_class Notepad")
#IfWinActive, ahk_class Notepad
	Shift & WheelDown::
		MsgBox, % "Notepad is active!"
	Return
;#If
#IfWinActive

Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: #if interferes with normal (outside) hotkeys [maybe a bug]

26 Jan 2016, 10:01

The #IfWinActive portion of your code works for me. It is the ^+WheelDown:: that fails on my system. Unfortunately, I have no idea why that is.
User avatar
AlphaBravo
Posts: 586
Joined: 29 Sep 2013, 22:59

Re: #if interferes with normal (outside) hotkeys [maybe a bug]

26 Jan 2016, 10:34

not sure why but when using +WheelDown instead it works

Code: Select all

^+WheelDown::
	ToolTip, % "Hello World!"
Return
 
^+WheelUp::
	ToolTip, % "I'm still working."
Return
 
#IfWinActive, ahk_class Notepad
	+WheelDown::
		ToolTip, % "Notepad is active!"
	Return
#IfWinActive
lexikos
Posts: 9688
Joined: 30 Sep 2013, 04:07
Contact:

Re: #if interferes with normal (outside) hotkeys [maybe a bug]

26 Jan 2016, 20:57

Shift + WheelDown corresponds to your custom hotkey even if you are holding other keys, and even if the hotkey isn't currently active. This is why you should not use the "custom combination" syntax with standard modifier keys.
aaurteo
Posts: 9
Joined: 28 Dec 2015, 01:42

Re: #if interferes with normal (outside) hotkeys [maybe a bug]

29 Jan 2016, 10:56

lexikos wrote:Shift + WheelDown corresponds to your custom hotkey even if you are holding other keys, and even if the hotkey isn't currently active. This is why you should not use the "custom combination" syntax with standard modifier keys.
Hi lexikos, very thank you and grateful of your reply. Feel like honored!
But could you explain in another way what you said? I'm sorry but I can't understand. Well, do you mean that a custom combination like below

1 & 2::
msgbox, % "hello"
return

will prevent 1 from being written?

Anyway, my original question was because a custom combination under a #if statement like below affects other hotkeys outside the #if.

#IfWinActive, ahk_class Notepad
Shift & WheelDown::

I think it shouldn't happen. (I understand that it should happen without a #if)
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: #if interferes with normal (outside) hotkeys [maybe a bug]

29 Jan 2016, 11:09

aaurteo wrote:
lexikos wrote:Shift + WheelDown corresponds to your custom hotkey even if you are holding other keys, and even if the hotkey isn't currently active. This is why you should not use the "custom combination" syntax with standard modifier keys.
Hi lexikos, very thank you and grateful of your reply. Feel like honored!
But could you explain in another way what you said? I'm sorry but I can't understand. Well, do you mean that a custom combination like below

1 & 2::
msgbox, % "hello"
return

will prevent 1 from being written?

Anyway, my original question was because a custom combination under a #if statement like below affects other hotkeys outside the #if.

#IfWinActive, ahk_class Notepad
Shift & WheelDown::

I think it shouldn't happen. (I understand that it should happen without a #if)

Using 1 & 2:: will indeed stop 1 from working by itself. Placing it inside a #IfWinAcive section will not change this due to limitations of the way AutoHotkey processes the #If directives.
lexikos
Posts: 9688
Joined: 30 Sep 2013, 04:07
Contact:

Re: #if interferes with normal (outside) hotkeys [maybe a bug]

29 Jan 2016, 18:48

aaurteo wrote:But could you explain in another way what you said? I'm sorry but I can't understand. Well, do you mean that a custom combination like below

1 & 2::
...
No, I think you completely missed the point. 1 & 2 is a custom combination of two keys, and "1" is not normally a modifier key. This is what custom combinations are for.

1 & 2:: will be triggered even if you press Ctrl+1+2, or Ctrl+Shift+1+2, assuming your keyboard hardware can handle it. This is fine, because hotkeys like ^1 & 2:: are invalid. Custom combinations only allow combinations of two keys, so there's no conflict like in your OP.

Shift & WheelDown:: is using the "custom combination" syntax, but it's just a standard combination. There's no reason to use the "custom combination" syntax for this hotkey.
Anyway, my original question was because a custom combination under a #if statement like below affects other hotkeys outside the #if.
The documentation doesn't say how #If will affect other hotkeys, only how it affects variants/duplicates of that hotkey.

The problem is that you are being inconsistent: using Shift in a custom combination and in standard combinations. You will have similar problems if you are inconsistent with key names - i.e. Ctrl vs Control, Esc vs Escape, 1 vs vk31, etc.
I think it shouldn't happen.
It won't happen if you use the appropriate syntax.
Shadowpheonix wrote:Using 1 & 2:: will indeed stop 1 from working by itself. Placing it inside a #IfWinAcive section will not change this
You are mistaken.

When you press 1, AutoHotkey sees that it is a prefix key, and evaluates the #If criteria of each hotkey using that prefix key. If none of them are "active" at the time the prefix key is pressed, it is not blocked.


@aaurteo & @Shadowpheonix: Don't quote the entire post when replying to the last post in the thread. It serves no purpose other than to fill the page with redundant (i.e. useless) text. Either quote relevant piece(s) of the post, or use the Post Reply button, not the Quote button.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Xeilous and 97 guests