Skip to content

Commit

Permalink
fix: windows: AltGr maps to LEFT_CTRL+RIGHT_ALT
Browse files Browse the repository at this point in the history
On Windows, some keyboard layouts have an AltGr button that's similar to
the Mac options button and can be used to send characters.
This PR respects the AltGr button and treat its characters as bubbletea
key runes.

Fixes: #1126
  • Loading branch information
aymanbagabas committed Sep 19, 2024
1 parent bd77483 commit ee083a3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions key_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ func keyType(e coninput.KeyEventRecord) KeyType {
case coninput.VK_DELETE:
return KeyDelete
default:
if e.ControlKeyState&(coninput.LEFT_CTRL_PRESSED|coninput.RIGHT_CTRL_PRESSED) == 0 {
switch {
case e.ControlKeyState.Contains(coninput.LEFT_CTRL_PRESSED) && e.ControlKeyState.Contains(coninput.RIGHT_ALT_PRESSED):
// AltGr is pressed, then it's a rune.
fallthrough
case !e.ControlKeyState.Contains(coninput.LEFT_CTRL_PRESSED) && !e.ControlKeyState.Contains(coninput.RIGHT_CTRL_PRESSED):
return KeyRunes
}

Expand Down Expand Up @@ -334,7 +338,7 @@ func keyType(e coninput.KeyEventRecord) KeyType {
case '\x1a':
return KeyCtrlZ
case '\x1b':
return KeyCtrlCloseBracket
return KeyCtrlOpenBracket // KeyEscape
case '\x1c':
return KeyCtrlBackslash
case '\x1f':
Expand All @@ -344,6 +348,8 @@ func keyType(e coninput.KeyEventRecord) KeyType {
switch code {
case coninput.VK_OEM_4:
return KeyCtrlOpenBracket
case coninput.VK_OEM_6:
return KeyCtrlCloseBracket
}

return KeyRunes
Expand Down

0 comments on commit ee083a3

Please sign in to comment.