0

I would like to launch the Bash shell included with the Windows Subsystem for Linux (WSL) via a keyboard hotkey.

I recently learned it is possible to assign a keyboard hotkey for an application by assigning a key combination in the application's shortcut's properties dialogue box.

This works well for regular applications. For example I assigned the hotkey for a terminal app to ctrl+f11. Upon pressing the respective key combination the application launches.

Snip: working application's shortcut properties:

edit: The shortcut is located in the start menu folder

enter image description here

If I assign a hotkey to a shortcut I created for the Bash.exe file located at C:\Windows\System32\bash.exe the bash shell does not run upon pressing the assigned key combination as I had expected it to.

Snip: Bash.exe shortcut properties:

Edit: The shortcut is located in a sub directory on the D:\ Drive

enter image description here

I was wondering what the reason for this might be and if there might be some way to work around this limitation without installing third party apps such as "AutoHotKey".

Thanking you,

  • 1
    Can not reproduce your issue in my PC. Ctrl+F12 works with bash.exe. – Biswapriyo Oct 23 at 19:05
  • @Biswapriyo Could you please share the location/path (../program files, ../desktop etc..) of the bash shortcut you have assigned the hotkey from. – Sameer Oct 23 at 19:16
  • Go to System32 folder in File Explorer > Right click on the bash.exe > Send to > Desktop (create shortcut) > shortcut will be in Desktop folder > Right click on that lnk file > Set the shortcut key. – Biswapriyo Oct 23 at 20:20
  • @Biswapriyo I discovered the reason it was not working for me was because I keep important shortcuts located in a folder on the D:\ drive. To not clutter the desktop and so I can prevent them from being deleted when I load my image backup of the primary hard drive. I see now that is not possible. Thankyou very much for helping, it is much appreciated. – Sameer Oct 23 at 20:30
0

The mystery is deeper than you think: Some keyboard shortcuts work, but others do not.

Example of what does not work : F12

Examples of what worked :

  • F10
  • Ctrl+Alt+O
  • Ctrl+F12 (sometimes)

In addition, after it worked once with one hotkey, it seems to work better with others. For example, your shortcut of Ctrl+F12 did not work at the beginning. But after F10 worked once for me, I went back to it and it worked this time. However, the shortcut of F12 by itself never worked for me.

As a further remark, it seems that shortcuts that contain Ctrl have a greater chance of working.

Conclusion: WSL has a funny implementation. Only a Microsoft developer of WSL could possibly unravel this mystery.

Notes:

  • I'm using WSL 1, not WSL 2
  • The startup time of bash.exe is long, so wait a couple of seconds before deciding that some shortcut doesn't work.

I wonder if you can reproduce these findings on your side.

  • It is possible the behavior you are describing is caused by some conflicting/overlapping or Windows reserved hotkeys. That is I believe separate from this behavior, fortunately I discovered the cause of the issue. According to the Microsoft support site "Shortcut keys work only for shortcuts on the desktop or in the Start menu hierarchy". support.microsoft.com/en-us/help/134552/… . Pinning the Bash.exe to the start menu first and applying the hotkey to that instance of the shortcut fixed the problem. – Sameer Oct 23 at 19:24
  • I am now however wondering where this "link" between shortcut and hotkey is stored and if possible to modify the entries from the registry. – Sameer Oct 23 at 19:28
  • It works for me without that for most keys. – harrymc Oct 23 at 19:39
  • Could you please share where the shortcut is located? On my end it doesn't work when the shortcut is placed in a folder other than the Start menu hierarchy. Thank you – Sameer Oct 23 at 19:56
  • On the desktop, created with right-click and New, and it looks exactly like your screenshot. – harrymc Oct 23 at 19:58
0

According to the Microsoft support website the behavior of shortcut hotkeys is described as such:

"Shortcut keys work only for shortcuts on the desktop or in the Start menu hierarchy"

Source: Shortcut key for shortcut does not work

It is stated that Shortcut hotkeys behave differently depending on where the shortcuts are located.

  • If the shortcut is located in the desktop folder or the start menu hierarchy ieWindows\Start Menu,Windows\Start Menu\Programs the hotkey will work to launch the respective application.

  • If the shortcut is not located on the desktop or within the Start menu hierarchy, the hotkey will work to switch focus to the assigned application only if it is already running

  • Shortcut hotkeys are also described as not being able to work for certain programs such as items in the quick launch bar

In this case, bash.exe had a shortcut which was located in a sub directory on the D:\ Drive. This will not work as explained above.

Instead, by pinning the bash.exe to the start menu, a shortcut is created in the

C:\Users\<UserName>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs folder.

By applying the hotkey to that shortcut the bash shell is launching with its respective hotkey.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.