Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ee083a3

Browse files
committedSep 19, 2024··
fix: windows: AltGr maps to LEFT_CTRL+RIGHT_ALT
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
1 parent bd77483 commit ee083a3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed
 

‎key_windows.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,11 @@ func keyType(e coninput.KeyEventRecord) KeyType {
274274
case coninput.VK_DELETE:
275275
return KeyDelete
276276
default:
277-
if e.ControlKeyState&(coninput.LEFT_CTRL_PRESSED|coninput.RIGHT_CTRL_PRESSED) == 0 {
277+
switch {
278+
case e.ControlKeyState.Contains(coninput.LEFT_CTRL_PRESSED) && e.ControlKeyState.Contains(coninput.RIGHT_ALT_PRESSED):
279+
// AltGr is pressed, then it's a rune.
280+
fallthrough
281+
case !e.ControlKeyState.Contains(coninput.LEFT_CTRL_PRESSED) && !e.ControlKeyState.Contains(coninput.RIGHT_CTRL_PRESSED):
278282
return KeyRunes
279283
}
280284

@@ -334,7 +338,7 @@ func keyType(e coninput.KeyEventRecord) KeyType {
334338
case '\x1a':
335339
return KeyCtrlZ
336340
case '\x1b':
337-
return KeyCtrlCloseBracket
341+
return KeyCtrlOpenBracket // KeyEscape
338342
case '\x1c':
339343
return KeyCtrlBackslash
340344
case '\x1f':
@@ -344,6 +348,8 @@ func keyType(e coninput.KeyEventRecord) KeyType {
344348
switch code {
345349
case coninput.VK_OEM_4:
346350
return KeyCtrlOpenBracket
351+
case coninput.VK_OEM_6:
352+
return KeyCtrlCloseBracket
347353
}
348354

349355
return KeyRunes

0 commit comments

Comments
 (0)
Please sign in to comment.