hluk / CopyQ

Clipboard manager with advanced features
GNU General Public License v3.0
8.69k stars 441 forks source link

Some keyboard shortcuts don't get mapped on Windows restart #1323

Open pbodnar opened 4 years ago

pbodnar commented 4 years ago

Describe the bug If I set a global keyboard shortcut like Ctrl+` for a command, it doesn't get mapped (i. e. it doesn't do anything) after Windows restarts. The same happens after user logout and login. But when I use a shortcut like Ctrl+Alt+B, there is no problem.

Workaround (how to avoid the problem) 1) Always start Windows / CopyQ with English, 2) don't forget to have English activated when assigning new shortcuts or when saving the CopyQ preferences. And "English" can be possibly exchanged for any other keyboard layout preferred by a user.

To Reproduce Steps to reproduce the behavior:

  1. Go to the CopyQ's preferences window, switch to the Shortcuts tab.
  2. Assign shortcut Ctrl+` to the Show/hide main window command.
  3. Close the window.
  4. Press the shortcut - the CopyQ's window appears = correct.
  5. Switch to a different keyboard layout (e. g. from English to Czech).
  6. Press the shortcut - the CopyQ's window disappears = correct.
  7. Log off from Windows and log in again.
  8. Press the shortcut - the CopyQ's window doesn't appear = BUG.

Expected behavior Any shortcut assigned to a command should work at any moment, including the moment after Windows restart.

Screenshots n/a

Version, OS and Environment

Additional context I guess that this might have something to do with a keyboard layouts "collision" - like that maybe mapping a pressed character works differently when CopyQ gets started automatically on Windows start. (There is also a weird Windows behavior that Alt+Shift won't switch keyboards until Win+Space is pressed or until an application is launched & focused.)

Note that there is also a historical bug #427 that coped with keyboard shortcuts and which might be related to this one.

hluk commented 4 years ago

Thanks for detailed description.

Can you also reproduce it by just restarting the app (Ctrl+Q and start again)? Maybe the shortcuts are not loaded properly at application start.

If it's a keyboard layout problem: Can you try assigning the shortcut when each layout is active? There is some platform-specific key code translation that could cause the issue.

pbodnar commented 4 years ago

Can you also reproduce it by just restarting the app (Ctrl+Q and start again)? Maybe the shortcuts are not loaded properly at application start.

That's it! :) Firstly, I wanted to write "sorry, I forgot to mention that starting the app manually is the 2nd workaround". But now that I have tested it again, the problem is unveiled:

  1. Start the app when having Czech keyboard active -> shortcut fails. (equivalent of Windows start)
  2. Start the app when having English keyboard active -> shortcut works.

Conclusion: At application start the shortcuts loading is dependent on the current keyboard layout.

So a quick & dirty fix would be probably to run the same code as you run when saving the preferences dialog, just after you load the shortcuts at application start.

hluk commented 4 years ago

Hmm, so if you go to shortcut tab in preferences and press OK to apply (event thought there are no changes) the shortcuts work again?

Is there any warning or error in log (F12 shortcut from main window)?

pbodnar commented 4 years ago

Yes, exactly. It's 100% reproducible on my pc, but I can test it on my second pc on Monday for sure.

In the log there is nothing special, only some "Connection lost" error messages from yesterday, no log items from today's testing, for example...

pbodnar commented 4 years ago

Update: Sorry for a confusion, but this is a really tricky bug: One needs to have English keyboard activated before clicking OK in the preferences. So when for example Czech is activated, the layout-dependent shortcut stops working. No need for restarts to reproduce.

hluk commented 4 years ago

Hmm, I think I would need to change this code, but I have no idea how.

Can you set multiple shortcuts for each layout? I know there could be potential conflicts but this is the only workaround I can think of -- unless you set the shortcut in desktop environment.

pbodnar commented 4 years ago

Hmm, I think I would need to change this code, but I have no idea how.

I'm not a Windows API expert myself, so I cannot help with this right now. I only slightly remember there was a possibility to listen for "virtual key" code (given by the key position on keyboard) instead for a translated character code...

Can you set multiple shortcuts for each layout? I know there could be potential conflicts but this is the only workaround I can think of -- unless you set the shortcut in desktop environment.

Yes, it looks like CopyQ lets you add a command multiple times and assign differing keystrokes to the command instances, but that's not that practical as having just one keystroke to remember.

Anyway, the current workaround doesn't luckily require too much hassle: 1) always start Windows / CopyQ with English, 2) don't forget to have English activated when assigning new shortcuts or when saving the CopyQ preferences. And "English" can be possibly exchanged for any other keyboard layout preferred by a user.

hluk commented 4 years ago

Yes, it looks like CopyQ lets you add a command multiple times and assign differing keystrokes to the command instances

You can assign multiple shortcuts to one command (in Command dialog or Shortcuts configuration tab in Preferences). Just click on the + button next to the shortcut.

image

Not sure if it would work but you can try assigning the shortcut, then switch keyboard layout and assign the shortcut again (presumably GUI will show different shortcut).

pbodnar commented 4 years ago

Oh, that's cool, I haven't noticed this feature :) Still, CopyQ won't let me assign the same keystroke multiple times: the same keystroke is not accepted by the GUI even though I switch the layout as suggested. Tried from both, the Command dialog and Shortcuts configuration tab.