Jump to content

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

Intercepting key strokes


  • Please log in to reply
1 reply to this topic
bohlinger
  • Members
  • 2 posts
  • Last active: Mar 09 2004 07:08 AM
  • Joined: 08 Mar 2004
Hello,
I don't understand the underlying logic about key stroke interception.
My example:
For a given application "A" I want a given key stroke to be intercepted and served. For all other application different from "A" I don't want the key stroke to be intercepted.
I found a way to do what I want but I'm not satisfied with the way for coding it:

;; I want the simple key pressed "d" to be a trigger when a given window, say "foo" is active.
;; For all other window different from "foo" I don't want anything done but the application behavior for that trigger.

$d::
IfWinActive, foo
{
MsgBox, do something
}
else
{ Send, d
}
return

I should have prefered the following encoding:
d::
IfWinActive, foo
{
MsgBox, do something
}
return

Regards,

Claude Bohlinger

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I know what you mean. As far as I can tell, it's impossible for the program to know whether you want a key to have it's native function or not. For the vast majority of hotkeys, the user does not want the hotkey to be "seen" by the active window. This is why the default behavior is to suppress (hide) the hotkey's own keystrokes. If you want to override that default, you have to code it yourself (as you did). I don't see that there's any other way to implement it.

However, one thing that may be useful to you is the following. Note the ~ prefix before the hotkey.

~d::
IfWinActive, foo
{
MsgBox, do something
}
return

What this does is make the letter D perform its native function while simultaneously activating the hotkey. However, this might be undesirable if if the "foo" window would receive the letter D and act upon it (if foo is a text editor, for example).