AutoHotkey Community

It is currently May 27th, 2012, 12:00 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: November 28th, 2010, 5:46 am 
Offline

Joined: November 28th, 2010, 5:38 am
Posts: 50
Location: Germany
Hi,
why does the following AHK-Script produce the warning mentioned in the subject when pressing "x"?

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


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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2010, 7:34 am 
you need to drop this:
Code:
$x:: Send x

Then it should work.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2010, 5:09 pm 
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:
Code:
#IfWinActive ahk_class Notepad
    $x::
#IfWinActive
x:: Send x


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2010, 5:20 pm 
quoteing from here http://www.autohotkey.com/docs/commands ... Active.htm
Quote:
#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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2010, 5:40 pm 
Offline

Joined: November 28th, 2010, 5:38 am
Posts: 50
Location: Germany
@gamax92
The line
Quote:
$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
Code:
#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
Code:
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
Code:
#IfWinActive ahk_class Notepad
    $x::
#IfWinActive


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2010, 5:51 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2010, 9:42 pm 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Where's your Return?

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 28th, 2010, 10:05 pm 
HjP wrote:
Code:
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:
Code:
$x:: Send x
#IfWinActive ahk_class Notepad
    x::
#IfWinActive


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 29th, 2010, 4:38 am 
Offline

Joined: November 28th, 2010, 5:38 am
Posts: 50
Location: Germany
@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).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 11th, 2010, 9:37 am 
Offline

Joined: November 28th, 2010, 5:38 am
Posts: 50
Location: Germany
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 20th, 2011, 5:22 am 
Offline

Joined: February 19th, 2010, 6:11 pm
Posts: 150
Location: California
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:

Code:
#IfWinActive AnyName
    x::
Return

#IfWinActive
$x:: Send x
Return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 20th, 2011, 9:26 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
If you use ListHotkeys with HjP's original script, it will show a single reg hotkey:
Code:
Type   Off?   Running   Name
-------------------------------------------------------------------
reg                     x

There are two reasons for this:
  1. $ must be applied to the first instance of the hotkey.
  2. #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.
HjP wrote:
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:
Code:
#IfWinActive AnyName
x::
#IfWinActive OtherName
x::
#IfWinActive  ; Reset for any other hotkeys below.
    Send x
return

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2011, 2:21 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
The following change has been made in v1.1.00.01:
Quote:
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 26 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group