mirror of
https://github.com/sst/opencode.git
synced 2025-09-12 16:06:20 +00:00
fix(windows): resolve numlock and French keyboard input issues (#1165)
This commit is contained in:
parent
6232e0fc58
commit
8bf2eeccd0
1 changed files with 47 additions and 25 deletions
|
@ -463,29 +463,42 @@ func (p *Parser) parseWin32InputKeyEvent(state *win32InputState, vkc uint16, _ u
|
||||||
baseCode = KeyMediaStop
|
baseCode = KeyMediaStop
|
||||||
case vkc == xwindows.VK_MEDIA_PLAY_PAUSE:
|
case vkc == xwindows.VK_MEDIA_PLAY_PAUSE:
|
||||||
baseCode = KeyMediaPlayPause
|
baseCode = KeyMediaPlayPause
|
||||||
case vkc == xwindows.VK_OEM_1:
|
case vkc == xwindows.VK_OEM_1, vkc == xwindows.VK_OEM_PLUS, vkc == xwindows.VK_OEM_COMMA,
|
||||||
|
vkc == xwindows.VK_OEM_MINUS, vkc == xwindows.VK_OEM_PERIOD, vkc == xwindows.VK_OEM_2,
|
||||||
|
vkc == xwindows.VK_OEM_3, vkc == xwindows.VK_OEM_4, vkc == xwindows.VK_OEM_5,
|
||||||
|
vkc == xwindows.VK_OEM_6, vkc == xwindows.VK_OEM_7:
|
||||||
|
// Use the actual character provided by Windows for current keyboard layout
|
||||||
|
// instead of hardcoded US layout mappings
|
||||||
|
if !unicode.IsControl(r) && unicode.IsPrint(r) {
|
||||||
|
baseCode = r
|
||||||
|
} else {
|
||||||
|
// Fallback to original hardcoded mappings for non-printable cases
|
||||||
|
switch vkc {
|
||||||
|
case xwindows.VK_OEM_1:
|
||||||
baseCode = ';'
|
baseCode = ';'
|
||||||
case vkc == xwindows.VK_OEM_PLUS:
|
case xwindows.VK_OEM_PLUS:
|
||||||
baseCode = '+'
|
baseCode = '+'
|
||||||
case vkc == xwindows.VK_OEM_COMMA:
|
case xwindows.VK_OEM_COMMA:
|
||||||
baseCode = ','
|
baseCode = ','
|
||||||
case vkc == xwindows.VK_OEM_MINUS:
|
case xwindows.VK_OEM_MINUS:
|
||||||
baseCode = '-'
|
baseCode = '-'
|
||||||
case vkc == xwindows.VK_OEM_PERIOD:
|
case xwindows.VK_OEM_PERIOD:
|
||||||
baseCode = '.'
|
baseCode = '.'
|
||||||
case vkc == xwindows.VK_OEM_2:
|
case xwindows.VK_OEM_2:
|
||||||
baseCode = '/'
|
baseCode = '/'
|
||||||
case vkc == xwindows.VK_OEM_3:
|
case xwindows.VK_OEM_3:
|
||||||
baseCode = '`'
|
baseCode = '`'
|
||||||
case vkc == xwindows.VK_OEM_4:
|
case xwindows.VK_OEM_4:
|
||||||
baseCode = '['
|
baseCode = '['
|
||||||
case vkc == xwindows.VK_OEM_5:
|
case xwindows.VK_OEM_5:
|
||||||
baseCode = '\\'
|
baseCode = '\\'
|
||||||
case vkc == xwindows.VK_OEM_6:
|
case xwindows.VK_OEM_6:
|
||||||
baseCode = ']'
|
baseCode = ']'
|
||||||
case vkc == xwindows.VK_OEM_7:
|
case xwindows.VK_OEM_7:
|
||||||
baseCode = '\''
|
baseCode = '\''
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if utf16.IsSurrogate(r) {
|
if utf16.IsSurrogate(r) {
|
||||||
if state != nil {
|
if state != nil {
|
||||||
|
@ -500,14 +513,18 @@ func (p *Parser) parseWin32InputKeyEvent(state *win32InputState, vkc uint16, _ u
|
||||||
// XXX: Should this be a KeyMod?
|
// XXX: Should this be a KeyMod?
|
||||||
altGr := cks&(xwindows.LEFT_CTRL_PRESSED|xwindows.RIGHT_ALT_PRESSED) == xwindows.LEFT_CTRL_PRESSED|xwindows.RIGHT_ALT_PRESSED
|
altGr := cks&(xwindows.LEFT_CTRL_PRESSED|xwindows.RIGHT_ALT_PRESSED) == xwindows.LEFT_CTRL_PRESSED|xwindows.RIGHT_ALT_PRESSED
|
||||||
|
|
||||||
|
// FIXED: Remove numlock and scroll lock states when checking for printable text
|
||||||
|
// These lock states shouldn't affect normal typing
|
||||||
|
cksForTextCheck := cks &^ (xwindows.NUMLOCK_ON | xwindows.SCROLLLOCK_ON)
|
||||||
|
|
||||||
var text string
|
var text string
|
||||||
keyCode := baseCode
|
keyCode := baseCode
|
||||||
if !unicode.IsControl(r) {
|
if !unicode.IsControl(r) {
|
||||||
rw := utf8.EncodeRune(utf8Buf[:], r)
|
rw := utf8.EncodeRune(utf8Buf[:], r)
|
||||||
keyCode, _ = utf8.DecodeRune(utf8Buf[:rw])
|
keyCode, _ = utf8.DecodeRune(utf8Buf[:rw])
|
||||||
if unicode.IsPrint(keyCode) && (cks == 0 ||
|
if unicode.IsPrint(keyCode) && (cksForTextCheck == 0 ||
|
||||||
cks == xwindows.SHIFT_PRESSED ||
|
cksForTextCheck == xwindows.SHIFT_PRESSED ||
|
||||||
cks == xwindows.CAPSLOCK_ON ||
|
cksForTextCheck == xwindows.CAPSLOCK_ON ||
|
||||||
altGr) {
|
altGr) {
|
||||||
// If the control key state is 0, shift is pressed, or caps lock
|
// If the control key state is 0, shift is pressed, or caps lock
|
||||||
// then the key event is a printable event i.e. [text] is not empty.
|
// then the key event is a printable event i.e. [text] is not empty.
|
||||||
|
@ -515,6 +532,11 @@ func (p *Parser) parseWin32InputKeyEvent(state *win32InputState, vkc uint16, _ u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Special case: numeric keypad divide should produce "/" text on all layouts (fix french keyboard layout)
|
||||||
|
if baseCode == KeyKpDivide {
|
||||||
|
text = "/"
|
||||||
|
}
|
||||||
|
|
||||||
key.Code = keyCode
|
key.Code = keyCode
|
||||||
key.Text = text
|
key.Text = text
|
||||||
key.Mod = translateControlKeyState(cks)
|
key.Mod = translateControlKeyState(cks)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue