Problem using a modifier key (on its own) as a hotkey

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Problem using a modifier key (on its own) as a hotkey

16 Mar 2020, 00:03

I use a lot of hotkey combinations that include the Win key. But if I don't press the keys carefully then the Win key can get accidentally pressed on its own (which opens the Start Menu and grabs focus from whatever program I'm using). This is annoying.

To deal with this problem, I wanted to make short key-pressing the Win key (on its own) do nothing, but still be able to use it to open the Start Menu when I long-press on it.

I used KeyWait to get separate long and short LWin key-press actions working, but it broke all my Win key hotkey combinations with other keys.

If I added a tilde ~ symbol before LWin, then my Win key combination hotkeys stated working again, but the long-press feature no longer worked and the Start Menu always triggered (even on a short key-press of the Win key).

How can I disable the Win key for short key-presses (when pressed on its on), while allowing it to open the Start Menu on a long-press, without this interfering with any of my other hotkey combinations that include the Win key?
Rohwedder
Posts: 7629
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Problem using a modifier key (on its own) as a hotkey

16 Mar 2020, 01:47

Hallo,
try:

Code: Select all

$LWin::
Send, {LWin Down}{vk07}
KeyWait, LWin, T.5
IF ErrorLevel
	Send, {LWin}
KeyWait, LWin
Send, {LWin Up}
Return
Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Re: Problem using a modifier key (on its own) as a hotkey

16 Mar 2020, 08:35

Thank you very much for your reply, Rohwedder.

This works, but there are a couple of issues for me (one minor, one major).

1. I'd ideally like to have a shorter delay if the Start Menu has focus (not the whole Taskbar, just ahk_class DV2ControlHost) because it feels weird having to long-press to close the Start Menu. I found myself repeatedly doing a shorter 'press and release' of the Win key wondering why it would not close. I don't want the delay removed completely when the Start Menu has focus, because there are still instances where I'd use a Win Key combination hotkey while the Start Menu is open, and so I still want to avoid the problem of accidentally pressing the Win key on its own when I'm trying to press a Win key combination.

Additionally (I don't know if this is possible in this particular case), I have other 'delayed action' hot keys that use if A_TimeSinceThisHotkey >= in combination with KeyWait to trigger either on key up or if the key contines to be held down (as long as the specified amount of time has elapsed) instead of only triggering when the key is held down. Would this be possible in this instance, without causing other issues?


2. A bigger problem for me is that the example code above interferes with the Show Desktop feature activated by the TrackPad on my laptop (a feature that I use constantly). If I do a 3-finger swipe down on my TrackPad it shows the Desktop; if I do another 3-finger swipe down it 'unshows' the Desktop and restores the previous windows. Unfortunately the way the TrackPad achieves this is by simply sending a Win D key press instead of actually sending a proper Show Desktop command. This means that any script action that I try to apply to the Win D hotkey also gets triggered by my TrackPad (which is not what I want). I therefore had to stop using my Win D modification script with the Win D hotkey and assign it a different hotkey (so that my TrackPad would continue to be able to send Win D unaffected). I do not know if there is a way to restrict a script to only affect keyboard presses and not commands coming from the TrackPad. It may be impossible to distinguish the two, seeing as the TrackPad is just sending a Win D key press anyway.

A similar issue applies to your example code (above). I tested the code on its own with no other scripts running, and I found that when I used my TrackPad to activate Show Desktop, it would not work and instead would only send the letter d. I could see this if I had a text editor open when I did the swipe. Each time I swiped on my TrackPad, the letter 'd' would be typed into my text editor. Strangely, if I actually press Win D using my keyboard (instead of using the TrackPad) Show Desktop still works.

It seems as if your code example is interfering with the ability of the TrackPad to send the Win Key; therefore only the letter 'd' gets sent (which breaks the Show Desktop function and sends unwanted key strokes to the currently focussed application because no modifier key is being used when the TrackPad tries to trigger Win D).
Rohwedder
Posts: 7629
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Problem using a modifier key (on its own) as a hotkey

16 Mar 2020, 10:54

I do not have a TrackPad for testing.
But, perhaps?
According to this script https://www.autohotkey.com/docs/commands/GetKey.htm#ExBasic
the codes of my Key LWin are VK5B and SC15B.
Therefore the Hotkey $LWin:: corresponds here $VK5B:: and $SC15B::.
Maybe one of these Hotkeys works better?
Lem2001
Posts: 127
Joined: 27 Jun 2017, 17:59

Re: Problem using a modifier key (on its own) as a hotkey

16 Mar 2020, 21:28

I tested using the provided script, and my key codes are the same as yours. I then tried the two alternative codes, but they resulted in the same problem.

I don't think this issue can be solved because of the stupid way that the TrackPad invokes the Show Desktop feature. If anything is done to affect how the Win key behaves, then this will automatically also affect the TrackPad (because the trackpad literally sends key presses in order to activate Show Desktop).

Thanks anyway for trying to help.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Fredrik F, Joey5, maxkill, Rohwedder and 389 guests