As I understand, Tk "emulates" X events when under Windows, and doesn't use MS-prescribed way to handle keyboard accelerators.

Check this line and function it resides in. Not sure I understand 100%, how come if I press "x" holding Ctrl, the function is called with same virtual keycode 88 for X key but (1) with "state" 8 for NumLock only and next (2) with "state" now 12 for Ctrl and NumLock. Return values are 120 (ascii x) and 24 (Ctrl-x).

Then it gets curiouser, whatever "keysym" this function returns appears to determine which, if any, accelerator to process, only. Keys pressed during "normal" input produce "normal" and expected characters displayed, regardless of changes I make, see further, to function. And more curioser, return "24" (in case of Ctrl-x) seems to be ignored and unused. But "keysym" returned for as-if-without-Ctrl call is important.

If you are still with me, the linked line misses the fact that under Latin and non-Latin kb-layouts, for the same virtual keycode (e.g. 88 for X key), the ToAscii populates 1st byte of "buf" with either 120 or 247, the latter is cyrillic "che" in CP1251 (these characters share the same key). So, with Russian kb-layout active, Ctrl-x doesn't cut in Tk.

Long story short, replace that line with:

static HKL USKB; if (!(int)USKB) USKB = LoadKeyboardLayout("00000409", 0); result = ToAsciiEx(keycode, scancode, keys, (LPWORD) buf, 0, USKB);

and then Ctrl-x, -c, -v work as expected under Russian layout, too. No idea if it's "right" way to fix the problem, though. Nor if it's acceptable for you to advise to compile Tk or distribute modified versions.

BTW, it's not true that "Ctrl-C" and friends work in Tk under US or any Latin keyboard. I mean, they don't if you press Ctrl-c with CapsLock active. Which doesn't contradict the description above and could be fixed if it bothers anybody (evidently not).


In reply to Re: Windows Tk issue Copy and Paste Russian keyboard by vr
in thread Windows Tk issue Copy and Paste Russian keyboard by IB2017

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.