Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

(Fixed) 71 hotkeys have been received in the last ..


  • Please log in to reply
12 replies to this topic
HjP
  • Members
  • 53 posts
  • Last active: Dec 05 2012 08:12 AM
  • Joined: 28 Nov 2010
Hi,
why does the following AHK-Script produce the warning mentioned in the subject when pressing "x"?

#IfWinActive AnyName
    x::
#IfWinActive
$x:: Send x

I use AutoHotkey v1.0.48.05.L61 and Windows 7 64bit.

gamax92
  • Guests
  • Last active:
  • Joined: --
you need to drop this:
$x:: Send x
Then it should work.

a4u
  • Guests
  • Last active:
  • Joined: --
I'm not sure if this is a bug - you're getting the error message because the hotkey code is triggering the hotkey, and causing an infinite loop. I would simply put the hook on the first instance of the hotkey:
#IfWinActive ahk_class Notepad

    $x::

#IfWinActive

x:: Send x


gamax92
  • Guests
  • Last active:
  • Joined: --
quoteing from here http://www.autohotke... ... Active.htm

#IfWinActive ahk_class Notepad
^!c::MsgBox You pressed Control+Alt+C in Notepad.
#IfWinActive ahk_class WordPadClass
^!c::MsgBox You pressed Control+Alt+C in WordPad.
#IfWinActive
^!c::MsgBox You pressed Control+Alt+C in a window other than Notepad/WordPad.


Soo... If the Notepad/WordPad window is not up, it doesn't use the other hotkey. So what popurse does it have to make a hot key to send its self.
Short answer, DONT PUT IT THERE.

HjP
  • Members
  • 53 posts
  • Last active: Dec 05 2012 08:12 AM
  • Joined: 28 Nov 2010
@gamax92
The line

$x:: Send x

should not send the hotkey to itself, since I used the modifier symbol "$". However it does send the hotkey to itself if there are also the lines
#IfWinActive AnyName
    x::
#IfWinActive
which actually shouldn't have any effect at all unless there's a certain window active.

@a4u
The code you presented is another form of the bug. Actually your code should trigger a warning message, since
x:: Send x
is a self-triggering Hotkey. However, for any strange reasons, the warning message does not occur if there are the additional lines
#IfWinActive ahk_class Notepad
    $x::
#IfWinActive


gamax92
  • Guests
  • Last active:
  • Joined: --
I know that. I actually had that problem once and figured if i take the line out, the message would go away. It still acts like its there.

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Where's your Return?

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


a4u
  • Guests
  • Last active:
  • Joined: --

x:: Send x
is a self-triggering Hotkey.

By itself - yes. However, I put a Hook on the first instance of the x-hotkey. If you want to argue that that hook shouldn't matter because it's in an #If-directive, you might have a good point. Also note, you could switch the order of the hotkey definitions, as long as the first hotkey definition has the hook:
$x:: Send x
#IfWinActive ahk_class Notepad
    x::
#IfWinActive


HjP
  • Members
  • 53 posts
  • Last active: Dec 05 2012 08:12 AM
  • Joined: 28 Nov 2010
@MasterFocus
Returns are not necessary, since the hotkey definitions comprise each only a single line. If you prefer, you may insert Returns; it doesn't affect the bug..

@a4u
Yes, the bug is that autohotkey evaluates the modifier of only one (the first) hotkey definition ignoring the fact that the two definitions are in different contexts (#directive).

HjP
  • Members
  • 53 posts
  • Last active: Dec 05 2012 08:12 AM
  • Joined: 28 Nov 2010
Hi,

could someone from the development section please confirm that this is a bug and provide some information as to whether or not there will be efforts to fix it.

Thanx,
HjP

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
This isn't a bug this is just badly written code.
The code you wrote was probably giving a error because the first x hotkey would run and trigger the "send x". Which would cause a infinite loop thus causing that error to appear.

You should of done:

#IfWinActive AnyName
    x::
Return

#IfWinActive
$x:: Send x
Return


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
If you use ListHotkeys with HjP's original script, it will show a single reg hotkey:
Type	Off?	Running	Name
-------------------------------------------------------------------
reg                     x
There are two reasons for this:
[*:239pzr96]$ must be applied to the first instance of the hotkey.

[*:239pzr96]#IfWin causes the keyboard hook to be used only if it is necessary. That is, the keyboard hook is normally required to decide whether the keystroke should be passed through to the system. Since in this case there is a global, non-suspended variant of the hotkey, it will necessarily never be passed through to the system, so the keyboard hook is not required.

Returns are not necessary, since the hotkey definitions comprise each only a single line.

The second hotkey is a single line hotkey. The first hotkey is not, since there is no command to the right of "::". It is similar to the following, which specifies multiple criteria for a single hotkey:
#IfWinActive AnyName
x::
#IfWinActive OtherName
x::
#IfWinActive  ; Reset for any other hotkeys below.
    Send x
return

y::MsgBox This hotkey is not context-sensitive.


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
The following change has been made in v1.1.00.01:

Fixed: $ and #UseHook had no effect if used only on the second or subsequent instance(s) of a hotkey.

Now if any instance of the hotkey has $ or #UseHook, it applies to all instances of that hotkey.