-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent handling of keyboard shortcuts with caps lock on #1565
Comments
So make |
Yes, obviously I can just write: environment-gadget "general" f {
{ T{ key-up f f "w" } add-word }
{ T{ key-up f f "W" } add-word }
} define-command-map But maybe it would be worth looking at how Factor handles keyboard gestures to see it there isn't a bug somewhere. |
@nicolas-p wait, I didn't read the bug report properly -- did you say in Factor on the mac that |
Yes, this is what happens. I guess you can easily check it yourself. |
Okay, so I don't use caps lock much (I rebind it to control), but I did some testing and found that apparently when the caps lock key is on the This "fixes" it, but I don't want to apply this change without understanding when and when not to uppercase the characters: diff --git a/basis/ui/backend/cocoa/views/views.factor b/basis/ui/backend/cocoa/views/views.factor
index 25b4359..6bea6ca 100644
--- a/basis/ui/backend/cocoa/views/views.factor
+++ b/basis/ui/backend/cocoa/views/views.factor
@@ -68,8 +68,10 @@ CONSTANT: key-codes
}
: key-code ( event -- string ? )
- dup -> keyCode key-codes at
- [ t ] [ -> charactersIgnoringModifiers CF>string f ] ?if ;
+ dup -> keyCode key-codes at [ t ] [
+ [ -> charactersIgnoringModifiers CF>string ]
+ [ -> modifierFlags NSAlphaShiftKeyMask bitand 0 > [ >upper ] when ] bi f
+ ] ?if ;
: event-modifiers ( event -- modifiers )
-> modifierFlags modifiers modifier ; |
On my side I had to do this. |
It works with Shift, just not Caps lock. |
On Windows the CapsLock state should not make a difference. It should be the same as on Mac. |
I don't think |
But ctrl-shift-s should not be the same as ctrl-s when caps is pressed. |
By the way, at least on Linux (and probably on Windows too) in the Listener UI, keyboard shortcuts don't work when capslock is on, like ctrl+a+caps doesn't "select all", for the same reason as noted upthread. It's a little bug that should probably be fixed before like, 0.99 but I only notice it because I press caps accidentally sometimes. |
For what it's worth, you can get a good idea of what events are being generated using IN: scratchpad USE: gesture-logger
IN: scratchpad run-gesture-logger I see, for example, a
|
For me it's like |
Wow, gesture-logger is a very cool tool, I didn't know it existed!
we should really have
And the character should always be lower-case independent of the CapsLock state. This would make the behavior consistent with all the (normal) Windows apps out there. |
I've pushed a patch here: https://github.com/AlexIljin/factor/tree/fix-1565 Pressing "a" without Caps Lock:
Pressing "S+a" without Caps Lock:
Pressing "a" with Caps Lock:
Pressing "S+a" with Caps Lock:
The above behavior is exactly what I would expect, as it would make sure that The only remaining issue is the duplicated Please, have a look and tell me what you think. |
I think my code which was showed on the Factor mailing list solves the duplicated key-down notification issue. |
Seems like we need to make sure all platforms are doing the same thing. So, either keep all keys as lowercase, with their modifiers. Or uppercase, with or without modifiers. Or, some other thing. Patches and investigation welcome! |
Previous comment code from the mailing list, for tracking. CONSTANT: wm-keydown-codes
H{
{ 48 "0" } ! <- added
{ 49 "1" } ! <- added
{ 50 "2" } ! <- added
{ 65 "a" } ! <- added
{ 66 "b" } ! <- added
{ 67 "c" } ! <- added
{ 8 "BACKSPACE" }
{ 9 "TAB" }
{ 13 "RET" }
{ 27 "ESC" }
{ 33 "PAGE_UP" }
{ 34 "PAGE_DOWN" }
{ 35 "END" }
{ 36 "HOME" }
{ 37 "LEFT" }
{ 38 "UP" }
{ 39 "RIGHT" }
{ 40 "DOWN" }
{ 45 "INSERT" }
{ 46 "DELETE" }
{ 112 "F1" }
{ 113 "F2" }
{ 114 "F3" }
{ 115 "F4" }
{ 116 "F5" }
{ 117 "F6" }
{ 118 "F7" }
{ 119 "F8" }
{ 120 "F9" }
{ 121 "F10" }
{ 122 "F11" }
{ 123 "F12" }
{ 190 "PERIOD" } ! <- added
}
:: key-sym ( wParam -- string/f action? ) ! : -> ::
! {
! {
! [ dup LETTER? ]
! [ shift? caps-lock? xor [ CHAR: a + CHAR: A - ] unless 1string f ]
! }
! { [ dup digit? ] [ 1string f ] }
! [ wm-keydown-codes at t ]
! } cond ;
wParam wm-keydown-codes at [ t ] [
wParam
{
{
[ dup LETTER? ]
[ shift? caps-lock? xor [ CHAR: a + CHAR: A - ] unless 1string f ]
}
{ [ dup digit? ] [ 1string f ] }
[ wm-keydown-codes at t ]
} cond
] if* ;
:: handle-wm-keydown ( hWnd uMsg wParam lParam -- )
wParam exclude-key-wm-keydown? [
wParam key-sym over [
dup ctrl? alt? xor or [ ! neccesary?
hWnd send-key-down
] [ 2drop ] if
] [ 2drop ] if
] unless ;
:: handle-wm-char ( hWnd uMsg wParam lParam -- )
wParam exclude-key-wm-char? [
ctrl? alt? xor [
wParam 1string
! [ f hWnd send-key-down ]
[ drop ]
[ hWnd window user-input ] bi
] unless
] unless ; |
I've created the PR #2126, which incorporates the key-down event deduplication. I've also updated all the key-down events like |
Going back to the original posting, this fix makes the behavior consistent between Mac and Windows regarding the Caps Lock state. |
Hmm... I wrote wm-keydown-codes which had most of keys. And I understood my idea was too simple. The problem is there are various international keyboards. For example, to input "+” with US keyboard is shift & "=". But, with Japanese Keyboard, it is shift & "-". If they want to zoom a document, should I wrote the code as { T{ key-down f { S+ } "=" } com-zoom } ? Or as { T{ key-down f { S+ } "-" } com-zoom } ? |
I wrote the code for "Plan 2". It is more conservative, put emphasis on compatibility. |
I found a bug in it. I'll fix it tonight. <-- I did it. |
Hopefully resolved in 08aa27a, please reopen if not. |
I have defined a keyboard shortcut like this:
On a Mac, it doesn't matter if caps lock is tuned on or off, pressing W always triggers the action. On Windows, it only works if caps lock is turned off.
I don't know what is the expected behaviour (in this particular case, I prefer the Mac behaviour), but this inconsistency across platforms is strange.
The text was updated successfully, but these errors were encountered: