| View previous topic :: View next topic |
| Author |
Message |
SAbboushi
Joined: 18 Sep 2004 Posts: 60
|
Posted: Wed Feb 23, 2005 8:04 pm Post subject: Can't send an {ESC} to the current window?? |
|
|
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
| 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 |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Wed Feb 23, 2005 8:19 pm Post subject: |
|
|
| For a hotkey to send itself, you have to use the hook, as described on the Remapping page. |
|
| Back to top |
|
 |
SanskritFritz
Joined: 17 Feb 2005 Posts: 283 Location: Hungary, Budapest
|
Posted: Wed Feb 23, 2005 8:52 pm Post subject: |
|
|
The only thing you need to change is:
_________________ Is there another word for synonym? |
|
| Back to top |
|
 |
SAbboushi
Joined: 18 Sep 2004 Posts: 60
|
Posted: Wed Feb 23, 2005 8:54 pm Post subject: |
|
|
Thanks jonny-
Using the hook solved my problem. The link you provided does not describe using hook for hotkeys to send itself. Is there something that gives more details on hook and what it is actually doing? |
|
| Back to top |
|
 |
SanskritFritz
Joined: 17 Feb 2005 Posts: 283 Location: Hungary, Budapest
|
Posted: Wed Feb 23, 2005 8:57 pm Post subject: |
|
|
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 |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Wed Feb 23, 2005 9:04 pm Post subject: |
|
|
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 |
|
 |
SAbboushi
Joined: 18 Sep 2004 Posts: 60
|
Posted: Wed Feb 23, 2005 9:08 pm Post subject: |
|
|
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 ):
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}?
I am wondering whether AHK is intercepting the Send, {ESC} but not doing anything with it??
jonny - thanks for the clarification  |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Wed Feb 23, 2005 9:11 pm Post subject: |
|
|
| 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 |
|
 |
SAbboushi
Joined: 18 Sep 2004 Posts: 60
|
Posted: Wed Feb 23, 2005 9:54 pm Post subject: |
|
|
| 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 |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Wed Feb 23, 2005 9:59 pm Post subject: |
|
|
| Precisely. |
|
| Back to top |
|
 |
SAbboushi
Joined: 18 Sep 2004 Posts: 60
|
Posted: Wed Feb 23, 2005 10:16 pm Post subject: |
|
|
| 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 |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Wed Feb 23, 2005 10:35 pm Post subject: |
|
|
| 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 |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Thu Feb 24, 2005 2:27 am Post subject: |
|
|
| 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 |
|
 |
|