1

I've installed Microsoft PowerToys and I want to configure PowerToys Run so that it launches when I press the Windows key on the keyboard.

The settings allow me to change the keyboard shortcut to something like Windows-R, but changing it to just Windows does not seem to be permitted.

I already am used to pressing Windows when I want to type the name of an application that I want to launch, and I want to use PowerToys Run instead of the default Windows behaviour because it is offline and faster. I would like to use the Windows key so that I don't have to retrain my muscle memory.

Flimm
  • 10,206
  • 5
  • 32
  • 40
  • 2
    Remapping the Windows key is possible, but is still a very bad idea. I recommend finding another key. – harrymc Jun 23 '22 at 15:04
  • @harrymc Why is it a bad idea? How can it be done? – Flimm Jun 23 '22 at 15:27
  • Just for the challenge, I did the mapping in my answer, without disabling all the numerous shortcuts in which this key takes part. – harrymc Jun 23 '22 at 15:32

2 Answers2

2

The idea in this answer was great, however, attempting to have it run PowerToys.exe didn't work. I've used that idea to create the following script that is working well.

Assuming that Alt+Space is currently mapped to your PowerToys Run, using AutoHotkey:

$LWin::
KeyWait, LWin, T0.2
If !ErrorLevel              ; if you hold the LWin key for less than 200 miliseconds...
    send {Alt Down}{Space Down}{Alt Up}{Alt Up}
Else                        ; but if it is held for more than that...
    Send, {LWin Down}       ; ...hold LWin down
KeyWait, LWin               ; and, in both cases, wait for it to be released
Send, {LWin Up}
Return

After installing AutoHotKey, put the above text in a file with an .ahk extension and double-click on it. Then short-press press the (Windows) key to see the result.

Of course, if you have PowerToys Run mapped to some other key chord, then make the appropriate adjustments in the script above to have it simulate pressing those keys.

NotTheDr01ds
  • 17,574
  • 4
  • 44
  • 81
Ali
  • 284
  • 2
  • 13
  • Just to be clear, the only difference with the other answer is this line, right? `send {Alt Down}{Space Down}{Alt Up}{Alt Up}` – Flimm Sep 30 '22 at 15:37
  • 1
    @Flimm That is correct. Ali identified an issue with the other answer, so I recommended the creation of a new answer. Edits shouldn't be made by other users that fundamentally change the answer, and this was a significant enough change IMHO that it deserved a new answer, rather than a comment. Subsequently, harrymc also updated the original answer with the same change (without attribution, unfortunately), but I don't know which one came first at this point, since they were both "1 hour ago". – NotTheDr01ds Sep 30 '22 at 16:42
1

It's actually possible to remap a tap on the left Windows key to doing something, while distinguishing it from the long press that is required when using this key as part of a shortcut such as Win+R.

You may use the free AutoHotkey.

The following script will do this. Replace if necessary the path to the powertoys executable (code modified as influenced by comment and answer of user Ali):

$LWin::
KeyWait, LWin, T0.2
If !ErrorLevel              ; if you hold the LWin key for less than 200 miliseconds...
    send {Alt Down}{Space Down}{Space Up}{Alt Up}   ; ...run powertoys launcher
Else                        ; but if it is held for more than that...
    Send, {LWin Down}       ; ...hold LWin down
KeyWait, LWin               ; and, in both cases, wait for it to be released
Send, {LWin Up}
Return

After installing AutoHotKey, put the above text in a .ahk file and double-click it to test. You may stop the script by right-click on the green H icon in the traybar and choosing Exit. To have it run on login, place it in the Startup group at
C:\Users\USER-NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.

Useful AutoHotkey documentation:

harrymc
  • 455,459
  • 31
  • 526
  • 924
  • Interesting! This does seem to activate when pressing the Windows key. Unfortunately, it launches the PowerToys Settings window, rather than the PowerToys Run launcher. And I'm guessing that launching a new process is not the most efficient. Is it possible to make it instead simulate pressing the real keyboard shortcut that would trigger PowerToys Run? – Flimm Jun 23 '22 at 15:39
  • Replace in the script `C:\Program Files\PowerToys\PowerToys.exe` by the right path to the PowerToys Run launcher. I don't have it installed, so can't tell which executable is it. If unsure, right-click the launcher in the Start menu and select Properties. – harrymc Jun 23 '22 at 15:43
  • 1
    I have modified you script in: https://github.com/microsoft/PowerToys/issues/5571#issuecomment-1236652943 – Ali Sep 05 '22 at 07:48
  • 1
    @Ali Agree that sending the PowerToys Run shortcut keys in response does improve the situation. Would recommend posting your modifications as a separate answer (with link and credit to harrymc's answer for the original idea). – NotTheDr01ds Sep 29 '22 at 13:52
  • @NotTheDr01ds I have created a new answer – Ali Sep 30 '22 at 15:07