 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
adante
Joined: 18 Apr 2009 Posts: 5
|
Posted: Wed Jun 10, 2009 2:37 pm Post subject: mapping lctrl for double-tap and while held down |
|
|
Hi,
I currently have a script which remaps my keyboard to do various shortcut functions when the left control is held down (I've remapped capslock to act as the ctrl button). The following code works nicely.
| Code: |
LCtrl::LHRemap("On")
LCtrl Up::LHRemap("Off")
|
Now I'd also like to make it so that a quick doubletap of the lctrl brings up google desktop search. The code from this post can do it nicely:
| Code: |
~LCtrl::
if (A_PriorHotKey = "~LCtrl" AND A_TimeSincePriorHotkey < 250)
Run "C:\Program Files\Google\Google Desktop Search\GoogleDesktop.exe"
Sleep 0
KeyWait LCtrl
return |
However I don't know how to integrate them together. When I try something like:
| Code: |
LCtrl::
if (A_PriorHotKey = "LCtrl" AND A_TimeSincePriorHotkey < 250)
Run "C:\Program Files\Google\Google Desktop Search\GoogleDesktop.exe"
else
LHRemap("On")
Sleep 0
KeyWait LCtrl
return
LCtrl Up::LHRemap("Off") |
this causes the remap to work, but now the A_PriorHotKey is always "LCtrl Up" for reasons I don't really understand. If I hook into that by changing the second line to:
| Code: | | if (A_PriorHotKey = "LCtrl Up" AND A_TimeSincePriorHotkey < 250) |
then the google desktop pops up, but now it acts as if ctrl is being held down. So if I type w, where I would expect the text 'w' to be inserted, it acts as if ctrl+w is pressed, which in google desktop tries to launch a browser for web search.
I'm not really sure what's happening here. How can I achieve both of the above functionalities? |
|
| Back to top |
|
 |
d-man
Joined: 08 Jun 2006 Posts: 285
|
Posted: Wed Jun 10, 2009 4:34 pm Post subject: |
|
|
| Why not just send a Control Up? Does that not work? |
|
| Back to top |
|
 |
animeaime
Joined: 04 Nov 2008 Posts: 1045
|
Posted: Wed Jun 10, 2009 4:37 pm Post subject: |
|
|
Try the combinations below. The "~" sends the key through. The computer thinks LCtrl is still pressed, because it is never told you released it. By sending the LCtrl up "event", the computer will think (as it should) that you released the LCtrl key.
| Code: | LCtrl::
;Tracks when the last time LCtrl was pressed
LCtrl_Time := A_TickCount
if (A_PriorHotKey = "~LCtrl Up" AND A_TickCount - LCtrl_Time < 250)
{
;if the last hotkey was the release of the LCtrl button and
;the you pressed LCtrl within 250ms (so a quick double tap)
Run "C:\Program Files\Google\Google Desktop Search\GoogleDesktop.exe"
else
LHRemap("On")
Sleep 0
KeyWait LCtrl
return
~LCtrl Up::LHRemap("Off") |
| adante wrote: | | but now the A_PriorHotKey is always "LCtrl Up" for reasons I don't really understand. |
That's because when you release the LCtrl button, the hotkey LCtrl Up is activated. Thus, the last hotkey IS LCtrl Up (or in the above case ~LCtrl Up).
However, since the last hotkey is LCtrl Up, A_TimeSincePriorHotkey shouldn't be used as the time checker, because it is the time since LCtrl was released (and not pressed like you want). So, to compensate, store A_TickCount in a variable (e.g. LCtrl_Time). Then, by subtracting LCtrl_Time from the current tick count, you can tell how many milliseconds it has been since you pressed LCtrl. If this is less than 250ms, then you pressed LCtrl twice within 250 ms (performing a "double click"), and your action is performed.
If the above doesn't work, no worries. Maybe you need a "~" also on LCtrl, or maybe it is something else. Regardless, I'm sure there is a solution to your problem - it just might take some playing around with to find it . _________________ As always, if you have any further questions, don't hesitate to ask.
Add OOP to your scripts via the Class Library. Check out my scripts. |
|
| Back to top |
|
 |
adante
Joined: 18 Apr 2009 Posts: 5
|
Posted: Thu Jun 11, 2009 10:03 am Post subject: |
|
|
| d-man wrote: | | Why not just send a Control Up? Does that not work? |
Thanks - I had previously tried SendInput {LCtrl Up} just before the Run "C:\..., while this didn't work your suggested made me try putting it the LCtrl Up hotkey. This seems to work:
| Code: | LCtrl::
if (A_PriorHotKey = "LCtrl Up" AND A_TimeSincePriorHotkey < 250)
Run "C:\Program Files\Google\Google Desktop Search\GoogleDesktop.exe"
else
LHRemap("On")
Sleep 0
KeyWait LCtrl
return
LCtrl Up::
SendInput {LCtrl Up}
LHRemap("Off")
return
|
Strangely I tried using a "~LCtrl Up" hotkey instead but this didn't work.
| animeaime wrote: | Try the combinations below. The "~" sends the key through. The computer thinks LCtrl is still pressed, because it is never told you released it. By sending the LCtrl up "event", the computer will think (as it should) that you released the LCtrl key.
| Code: | LCtrl::
;Tracks when the last time LCtrl was pressed
LCtrl_Time := A_TickCount
if (A_PriorHotKey = "~LCtrl Up" AND A_TickCount - LCtrl_Time < 250)
{
;if the last hotkey was the release of the LCtrl button and
;the you pressed LCtrl within 250ms (so a quick double tap)
Run "C:\Program Files\Google\Google Desktop Search\GoogleDesktop.exe"
else
LHRemap("On")
Sleep 0
KeyWait LCtrl
return
~LCtrl Up::LHRemap("Off") |
|
Thanks for your solution and explanation animeaime. I tried it with some modifications (I assume you meant to put LCtrl_Time := A_TickCount at the of the hotkey def, otherwise it will always activate on the second ctrl press) but it caused the same behaviour.
Anyway it's all working the way I want it now so it's academic. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|