AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Can't send an {ESC} to the current window??

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
SAbboushi



Joined: 18 Sep 2004
Posts: 60

PostPosted: Wed Feb 23, 2005 8:04 pm    Post subject: Can't send an {ESC} to the current window?? Reply with quote

I want the ESCAPE key to function differently for a specific application (Commence), but to be interpretted normally for all other apps. I tried the following code, but cannot get the ESCAPE key to function normally for all other applications Confused

Code:
ESCAPE::   ;   Commence changed so that Escape does not close child windows most of the time - ARGH!!  This puts it back
IfWinActive, Commence
   {
      Sleep 100
      Send, {CTRLDOWN}{F4}{CTRLUP}
   }
Else
   {
      Send, {ESC}

   }   


I have to suspend the script each time I need to use ESCAPE will all my applications except for Commence...

Can anyone suggest how to get around this?
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Wed Feb 23, 2005 8:19 pm    Post subject: Reply with quote

For a hotkey to send itself, you have to use the hook, as described on the Remapping page.
Back to top
View user's profile Send private message
SanskritFritz



Joined: 17 Feb 2005
Posts: 283
Location: Hungary, Budapest

PostPosted: Wed Feb 23, 2005 8:52 pm    Post subject: Reply with quote

The only thing you need to change is:
Code:
$Escape::

_________________
Is there another word for synonym?
Back to top
View user's profile Send private message
SAbboushi



Joined: 18 Sep 2004
Posts: 60

PostPosted: Wed Feb 23, 2005 8:54 pm    Post subject: Reply with quote

Thanks jonny-

Using the hook solved my problem. The link you provided does not describe using hook for hotkeys to send itself. Embarassed Is there something that gives more details on hook and what it is actually doing?
Back to top
View user's profile Send private message
SanskritFritz



Joined: 17 Feb 2005
Posts: 283
Location: Hungary, Budapest

PostPosted: Wed Feb 23, 2005 8:57 pm    Post subject: Reply with quote

http://www.autohotkey.com/docs/Hotkeys.htm

Quote:
This is usually only necessary if the script uses the Send command to send the keys that comprise the hotkey itself, which would otherwise cause it to fire unintentionally. The exact behavior of the $ prefix varies depending on operating system:

On Windows 95/98/Me and AutoHotkey v1.0.23+: The hotkey is disabled during the execution of its thread and re-enabled afterward. As a side-effect, if #MaxThreadsPerHotkey is set higher than 1, it will behave as though set to 1 for such hotkeys.

On other operating systems and for all versions of AutoHotkey: The $ prefix forces the keyboard hook to be used to implement this hotkey, which as a side-effect prevents the Send command from triggering it. The $ prefix is equivalent to having specified #UseHook prior to the definition of this hotkey.

_________________
Is there another word for synonym?
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Wed Feb 23, 2005 9:04 pm    Post subject: Reply with quote

This is a direct quote from the remapping page:

Quote:
#UseHook ; Needed for remapping keys to each other, e.g. A becomes B, and B becomes A.


It may not be entirely clear, but this also applies to remapping a key to itself.
Back to top
View user's profile Send private message
SAbboushi



Joined: 18 Sep 2004
Posts: 60

PostPosted: Wed Feb 23, 2005 9:08 pm    Post subject: Reply with quote

Thanks SanskritFritz-

Good info. Am confused by "... which would otherwise cause it to fire unintentionally." The Send, {ESC} in my code above does not seem to fire the hotkey again per my lines-executed log (not sure what to call that log Embarassed ):

787: IfWinActive,Commence
788: {
789: Send,{ESC} (0.03)
791: }
793: Exit (1.05)

So, since the script does send {ESC} and the {ESC} did not trigger the hotkey again (endless loop), I've been trying to figure out what happened to the {ESC}? Confused

I am wondering whether AHK is intercepting the Send, {ESC} but not doing anything with it??

jonny - thanks for the clarification Smile
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Wed Feb 23, 2005 9:11 pm    Post subject: Reply with quote

You are indeed right, that would cause an endless loop. Fortunately, should such a circumstance occur, AutoHotkey can recognize it and it won't carry out the Send. That's why you don't see it being fired.
Back to top
View user's profile Send private message
SAbboushi



Joined: 18 Sep 2004
Posts: 60

PostPosted: Wed Feb 23, 2005 9:54 pm    Post subject: Reply with quote

A-ha! Let me make sure I understand what you are saying jonny - are you saying that even though the AHK log for the script shows "789: Send,{ESC} (0.03) ", AHK prevented the line from being executed??
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Wed Feb 23, 2005 9:59 pm    Post subject: Reply with quote

Precisely.
Back to top
View user's profile Send private message
SAbboushi



Joined: 18 Sep 2004
Posts: 60

PostPosted: Wed Feb 23, 2005 10:16 pm    Post subject: Reply with quote

jonny - I don't mean to be a pest , but I thought the log showed the lines of code that were executed... this makes me wonder what other lines of code AHK reports in the log as having been executed, but were actually... not...
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Wed Feb 23, 2005 10:35 pm    Post subject: Reply with quote

I'm reasonably certain that this is the only instance you'll encounter something like this. To tell the truth, I had known about it grabbing the Send, but I hadn't known it would still show the line as being executed.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Thu Feb 24, 2005 2:27 am    Post subject: Reply with quote

SAbboushi wrote:
I thought the log showed the lines of code that were executed... this makes me wonder what other lines of code AHK reports in the log as having been executed, but were actually... not...
The "infinite loop" dialog doesn't always appear. In this case, I think since #MaxThreadsPerHotkey is at its default of 1, the infinite loop is aborted after the very first iteration.

AutoHotkey normally registers hotkeys via an OS feature. In this case, whenever you press Escape (or do Send {Esc}) the OS swallows the keystroke and notifies the script that you pressed it. To avoid this swallowing effect, you have to use the hook via #UseHook or the $ prefix.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group