fix: shortcuts with Option key#31
Conversation
Related to ParthJadhav#11. `event.key` returns transformed char when `option` key is pressed. For example, when user is trying to record shortcut `Option+Shift+G`, `event.key` returns `Option+Shift+˝`. `event.code` returns `KeyG` instead. So getting substring with offset 3 fixes this issue. This commit fixes another bug: when user records shortcut that already registered, window will hide. Adding `unregister` before start recording fixes this issue.
| shortcutArray = []; | ||
| hotkeys.unbind(); | ||
| // Prevent closing Preferences when recording already registered shortcut | ||
| unregister(preferences.get("shortcut")); |
There was a problem hiding this comment.
There would be an issue with this though...
For eg:
if I try executing setting CMD + Space which already is assigned to spotlight. When I click on the recorder, It will unregister the old shortcut but when I press CMD + Space spotlight would be opened. And hence there won't be a new registered shortcut & the previous shortcut would also be unregistered.
Leaving us with no shortcut to start the app 😄
There was a problem hiding this comment.
@ParthJadhav, I have the same issue on current master 🥲
There was a problem hiding this comment.
The problem is in hotkeys-js: it cannot capture last key of system hotkeys sequence
Screen.Recording.2023-01-06.at.21.14.36.mp4
So maybe we put this problem into another issue? Or you prefer resolve it in this PR? 🙂
|
Ohh, I see. That's alright. We will resolve it in different PR. This doesn't seem to be that important as of now |
|
Do you think this PR is ready to merge? |
Give me another five minutes to check production release 🫡 |
|
Got another bug when trying to set |
| } else { | ||
| shortcutArray.push(event.code.substring(3)); | ||
| } | ||
| const key = event.code.startsWith("Key") |
|
Also, quick question: do I need to squash commits or you prefer to preserve full history of changes? |
Oh dw, I'll directly do Squash & Merge |
|
TBH, The whole shortcut recorder function is messy & hard to understand. |
You can create issue and assign it to me, if you want. I can do some refactoring 🙂 |
|
I've tested it and everything works as expected... Except if anything else launches while setting the shortcut then we can only open the window by clicking the menu item |
Maybe we can do some researching for global shortcuts from Rust itself? I think Tauri do this under the hood, but maybe some other library can do this better... |
Oh no, Everything works as expected. But the fact that we unregister the key before recording the shortcut is causing the problem. What do you think? |
I think we can do it at later time when we find to be working on any issue related to the shortcut function... What are you opinion on it? |
I've tried to comment |
Great catch! I think the same way 🙂 |
|
Do you use Discord by any chance ? It would be easier to communicate there IMO 😄 |
Yes 🙂 |
Got it. So maybe I just drop this line and we put this in another issue? Also, we can do some refactoring just for resolving that kind of issues 🙂 |
Yep, lets do that 🙌 |
|
Awesome, Let's merge it 🚀 |

Related to #11.
event.keyreturns transformed char whenoptionkey is pressed.For example, when user is trying to record shortcut
Option+Shift+G,event.keyreturnsOption+Shift+˝.event.codereturnsKeyGinstead. So getting substring with offset 3 fixes this issue.This commit fixes another bug: when user records shortcut that already registered, window will hide. Adding
unregisterbefore start recording fixes this issue.