Windows Subsystem for Linux - Bash.exe keyboard hotkey

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,

Sameer

Posted 2019-10-23T18:03:27.713

Reputation: 1

1Can not reproduce your issue in my PC. Ctrl+F12 works with bash.exe. – Biswapriyo – 2019-10-23T19:05:59.193

@Biswapriyo Could you please share the location/path (../program files, ../desktop etc..) of the bash shortcut you have assigned the hotkey from. – Sameer – 2019-10-23T19:16:30.017

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 – 2019-10-23T20:20:15.020

@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 – 2019-10-23T20:30:54.867

Answers

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.

Sameer

Posted 2019-10-23T18:03:27.713

Reputation: 1

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.

harrymc

Posted 2019-10-23T18:03:27.713

Reputation: 306 093

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". https://support.microsoft.com/en-us/help/134552/shortcut-key-for-shortcut-does-not-work . Pinning the Bash.exe to the start menu first and applying the hotkey to that instance of the shortcut fixed the problem.

– Sameer – 2019-10-23T19:24:22.760

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 – 2019-10-23T19:28:02.140

It works for me without that for most keys. – harrymc – 2019-10-23T19:39:20.330

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 – 2019-10-23T19:56:27.210

On the desktop, created with right-click and New, and it looks exactly like your screenshot. – harrymc – 2019-10-23T19:58:46.170

Oh, Yes it is supposed to work If on the desktop or start menu hierarchy, other than that it is described to have a different behavior. I had previously placed the shortcut on the D:\ drive which was not working. – Sameer – 2019-10-23T20:00:44.777

You should have mentioned that first. Of course it won't work - there is no software that looks at that shortcut on D. Windows does not scan all drives for such links. Only the desktop and Start menu do implement it. – harrymc – 2019-10-23T20:05:39.097

There is still some weird stuff to do with WSL, but its integration with the Windows shell is still pretty good. – harrymc – 2019-10-23T20:06:52.250

Oh, yes that makes sense now, it was not something that i understood properly, I was under the impression some entry was made in the registry for each hot key irrespective of where it was located. I had hoped the screen shots would show where the shortcuts were located, but they are not very clear in portraying that, my mistake. Thank you very much for helping, it is much appreciated. And yes WSL does have some odd behavior here and there (mainly poor disk performance), im just really happy and amazed at how it works so seamlessly. Thank you again – Sameer – 2019-10-23T20:13:08.063

Appreciation for helpful answers on our site is shown by upvoting or accepting.

– harrymc – 2019-10-24T05:22:29.380

I understand, I did not have enough privileges to up vote as of yet, no option to upvote comments, and upvotes to answers are not registered. I have answered my own question, which I found to be the answer i was looking for, I can select my own answer as correct after a waiting period of two days. – Sameer – 2019-10-24T06:13:23.097