From a390fb7c79591cae68644f80ac0057f3c81ce5c5 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 23 Oct 2016 14:05:20 +0000 Subject: Fix [e36963bfe8]: event generate and diaeresis --- win/tkWinKey.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/win/tkWinKey.c b/win/tkWinKey.c index 31faea0..1ebf312 100644 --- a/win/tkWinKey.c +++ b/win/tkWinKey.c @@ -179,18 +179,18 @@ KeycodeToKeysym( { BYTE keys[256]; int result, deadkey, shift; - char buf[4]; + TCHAR buf[4]; unsigned int scancode = MapVirtualKey(keycode, 0); /* - * Do not run keycodes of lock keys through ToAscii(). One of ToAscii()'s + * Do not run keycodes of lock keys through ToUnicode(). One of ToUnicode()'s * side effects is to handle the lights on the keyboard, and we don't want * to mess that up. */ if (noascii || keycode == VK_CAPITAL || keycode == VK_SCROLL || keycode == VK_NUMLOCK) { - goto skipToAscii; + goto skipToUnicode; } /* @@ -231,24 +231,24 @@ KeycodeToKeysym( keys[VK_NUMLOCK] = 1; } - result = ToAscii(keycode, scancode, keys, (LPWORD) buf, 0); + result = ToUnicode(keycode, scancode, keys, buf, 4, 0); if (result < 0) { /* * Win95/98: This was a dead char, which is now remembered by the - * keyboard. Call ToAscii() again to forget it. + * keyboard. Call ToUnicode() again to forget it. * WinNT: This was a dead char, overwriting any previously remembered - * key. Calling ToAscii() again does not affect anything. + * key. Calling ToUnicode() again does not affect anything. */ - ToAscii(keycode, scancode, keys, (LPWORD) buf, 0); + ToUnicode(keycode, scancode, keys, buf, 4, 0); return XK_Multi_key; } if (result == 2) { /* * This was a dead char, and there were one previously remembered by - * the keyboard. Call ToAscii() again with proper parameters to + * the keyboard. Call ToUnicode() again with proper parameters to * restore it. * * Get information about the old char @@ -273,26 +273,26 @@ KeycodeToKeysym( if (shift & 4) { keys[VK_MENU] = 0x80; } - ToAscii(deadkey, scancode, keys, (LPWORD) buf, 0); + ToUnicode(deadkey, scancode, keys, buf, 4, 0); return XK_Multi_key; } /* - * Keycode mapped to a valid Latin-1 character. Since the keysyms for - * alphanumeric characters map onto Latin-1, we just return it. + * Keycode mapped to a valid Unicode character. Since the keysyms for + * alphanumeric characters map onto Unicode, we just return it. * * We treat 0x7F as a special case mostly for backwards compatibility. In * versions of Tk<=8.2, Control-Backspace returned "XK_BackSpace" as the X * Keysym. This was due to the fact that we did not initialize the keys - * array properly when we passed it to ToAscii, above. We had previously + * array properly when we passed it to ToUnicode, above. We had previously * not been setting the state bit for the Control key. When we fixed that, * we found that Control-Backspace on Windows is interpreted as ASCII-127 * (0x7F), which corresponds to the Delete key. * * Upon discovering this, we realized we had two choices: return XK_Delete * or return XK_BackSpace. If we returned XK_Delete, that could be - * considered "more correct" (although the correctness would be dependant - * on whether you believe that ToAscii is doing the right thing in that + * considered "more correct" (although the correctness would be dependent + * on whether you believe that ToUnicode is doing the right thing in that * case); however, this would break backwards compatibility, and worse, it * would limit application programmers; they would effectively be unable * to bind to on Windows. We therefore chose instead @@ -302,15 +302,15 @@ KeycodeToKeysym( * XK_BackSpace). */ - if (result == 1 && UCHAR(buf[0]) >= 0x20 && UCHAR(buf[0]) != 0x7F) { - return (KeySym) UCHAR(buf[0]); + if (result == 1 && buf[0] >= 0x20 && buf[0] != 0x7F) { + return (KeySym) buf[0]; } /* * Keycode is a non-alphanumeric key, so we have to do the lookup. */ - skipToAscii: + skipToUnicode: if (keycode > MAX_KEYCODE) { return NoSymbol; } @@ -565,7 +565,7 @@ TkpSetKeycodeAndState( } } if (keySym >= 0x20) { - result = VkKeyScan((char) keySym); + result = VkKeyScan((TCHAR) keySym); if (result != -1) { shift = result >> 8; if (shift & 1) @@ -618,7 +618,7 @@ XKeysymToKeycode( } } if (keysym >= 0x20) { - result = VkKeyScan((char) keysym); + result = VkKeyScan((TCHAR) keysym); if (result != -1) { return (KeyCode) (result & 0xff); } -- cgit v0.12 From f9816042fed0405176e42b8e150e111e698d0c3c Mon Sep 17 00:00:00 2001 From: fvogel Date: Sun, 30 Oct 2016 13:54:12 +0000 Subject: Added test event-8 to test the fix for for [e36963bfe8] --- tests/event.test | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/event.test b/tests/event.test index 756dbe5..7fce6c7 100644 --- a/tests/event.test +++ b/tests/event.test @@ -822,6 +822,41 @@ test event-7.2(double-click) {A double click on a lone character deleteWindows } -result {4 A 4 A} +test event-8 {event generate with keysyms corresponding to + multi-byte virtual keycodes - bug + e36963bfe8df9f5e528134707a91b9c0051de723} -setup { + deleteWindows + set res [list ] +} -body { + set t [toplevel .t] + set e [entry $t.e] + pack $e + tkwait visibility $e + bind $e {lappend res keycode: %k keysym: %K} + focus -force $e + update + event generate $e + # The value now contained in $res depends on the actual + # physical keyboard layout and keycode generated, from + # the hardware on which the test suite happens to run. + # We don't need (and we can't really) check correctness + # of the (system-dependent) keycode received, however + # Tk should be able to associate this keycode to a + # (system-independent) known keysym, unless the system + # running the test does not have a keyboard with a + # diaeresis key. + if {[expr {[lindex $res 3] ne "??"}]} { + # keyboard has a physical diaeresis key and bug is fixed + return "OK" + } else { + return "Test failed, unless the keyboard tied to the system \ + on which this test is run does NOT have a diaeresis \ + physical key - in this case, test is actually void." + } +} -cleanup { + deleteWindows +} -result {OK} + # cleanup unset -nocomplain keypress_lookup rename _init_keypress_lookup {} -- cgit v0.12