AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: March 22nd, 2010, 6:14 pm 
Offline

Joined: November 25th, 2004, 10:08 am
Posts: 57
jaco0646 wrote:
You can reproduce the behavior in this code.
Code:
a::b ;remap
a & b::MsgBox,% A_ThisHotkey ;prefix
The remapped a appears to do nothing because the prefix a blocks its down event, so only the a up hotkey fires, which in turn only produces b up, which produces nothing.


Hi again,

That doesn't quite explain the problem. While your example does cause the same behaviour, it doesn't do so in the same context as my original script. Within the context of the ACTIVE #IfWinActive block, the "a::b" type of remapping was not used. In it's context it would be closer to the following:

Code:
a::send b ;remap
a & b::MsgBox,% A_ThisHotkey ;prefix


which does work for both "a" alone and "a & b". However, the following code prevent "a" alone from working:

Code:
#IfWinActive ahk_class CabinetWClass ; a Windows explorer window
   a::c

#IfWinActive

a::send b ;remap
a & b::MsgBox,% A_ThisHotkey ;prefix


Here the "a::c" remap should only be active if an Explorer window is currently active. Therefore, if you attempt to type "a" while in a Notepad window, for instance, it should still work in principle. However, it does not, despite being in different contexts. The explanation you proposed of "a & b" inhibiting the "a" down press makes sense when they are operating in the same context, but doesn't make sense here becuase "a::send b" should override "a::c" unless Explorer is active.

The following code restores the correct behaviour of "a" in a non-Explorer window:

Code:
#IfWinActive ahk_class CabinetWClass
   a::send c

#IfWinActive

a::send b ;remap
a & b::MsgBox,% A_ThisHotkey ;prefix


Note, if you run this and type "a" into a Notepad window you will get "b". If you type "a" into the address bar of an Explorer window you'll get "c". So it works when written this way.

Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 23rd, 2010, 3:52 am 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
You're right. It seems a prefix key cannot be remapped, regardless of the #IfWin directive. :?
Edit: I've reported this as a bug for now: http://www.autohotkey.com/forum/viewtopic.php?t=56069.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2010, 6:53 pm 
Offline

Joined: November 25th, 2004, 10:08 am
Posts: 57
Thanks for reporting the bug (and your patients...).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 10th, 2011, 4:54 pm 
I'm very new to autohotkey, and I'm not sure if I've correctly understood your problem - so please forgive me if I've got the wrong end of the stick.

What I'm trying to do is remap the keys j and k to be backspace when pressed together, but to still work normally if pressed on their own. If this isn't essentially what you want to do, or there is some other reason why what I've done is bad then please just patiently ignore me.j

The following more or less works for me. You have to pause briefly after pressing and releasing the j, if you want to actually get the j keypress

Code:
j::Send j
j & f::
SetKeyDelay -1   ; If the destination key is a mouse button, SetMouseDelay is used instead.
Send {Blind}{Backspace DownTemp}
return

j & f up::
SetKeyDelay -1  ; See note below for why press-duration is not specified with either of these SetKeyDelays.
Send {Blind}{Backspace Up}
return


Report this post
Top
  
Reply with quote  
 Post subject: asasa
PostPosted: August 7th, 2011, 7:38 pm 
Offline

Joined: August 6th, 2011, 9:59 pm
Posts: 4
I think there might be some confusion here about how hotkey assignments work. I'm pretty sure that AHK hotkeys don't get "undefined" just because the block inside which they were defined stops being active.

In other words, doing this...
Code:
IfWinActive SomeApp
{
  ; define some hotkeys
}

...will define the hotkeys when SomeApp becomes active, but those hotkeys will then stay defined for all applications, even if the SomeApp window is no longer active.

To make a hotkey active only in one window you must either undefine it when the window stops being active, or test for the window within the macro itself (and optionally send the original key if some other window is active). In other words, you need to do something like this:

Code:
XButton1::
IfWinActive TheRelevantApp
    SendInput TheRelevantKeystrokes    ; what to send to this application
else
    MouseClick X1                      ; otherwise, send the original button
return


Adding other applications, if you need them, of course.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: chaosad, jrav, MSN [Bot] and 24 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