Tk Source Code

View Ticket
Login
Ticket UUID: e36963bfe8df9f5e528134707a91b9c0051de723
Title: event generate and diaeresis
Type: Bug Version: 8.6.4
Submitter: [email protected] Created on: 2016-07-28 10:01:33
Subsystem: 69. Events Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Critical
Status: Closed Last Modified: 2016-11-02 18:57:57
Resolution: Fixed Closed By: fvogel
    Closed on: 2016-11-02 18:57:57
Description:
Hello!

i just installed tk8.6.4 on Windows7.

There
	event generate .e <diaeresis>
	event generate .e <Udiaeresis>
	event generate .e <Adiaeresis>
	...
do nothing.

I.e.
        event generate .e <x>
is OK.


On Linux with tk8.6.1 "event generate"  works still fine.

Is this an Bug in 8.6.4? Or a TK/Windows-Problem?
Any ideas for an workaround?

Thanks for all help!
Matthias
(I posted this problem also on c.lang.tcl)
User Comments: fvogel added on 2016-11-02 18:57:57:
Yes it will be included in Tcl/Tk 8.6.7.

No I don't know when this will happen.

[email protected] added on 2016-11-02 16:05:07:
We tested this fix and it works fine! Thanks to everybody!

Will the fix be included in tcl8.6.7? Is there already an idea when the next release will be available?

Thanks
Matthias

jan.nijtmans added on 2016-11-01 10:23:31:
Well, the test passes in my environment, I don't have a better idea either. But the only way to get more feedback from people is getting this to core-8-6-branch and trunk, and see what happens. Maybe this test will have to be marked non-portable before the Tk 8.6.7 release, we'll see. At least, I think the fix is correct, that's what really matters.

Thanks! Whenever you get a better idea, please just go ahead! I'll do the same.

fvogel added on 2016-11-01 09:57:50:
What do you think about the test event-8 I have proposed?

I'm not so satisfied with it since it will fail (as a false alarm) if the test is run on a system having a keyboard without a diaeresis key. This test is therefore suboptimal but I don't have better ideas.

What do you think?

jan.nijtmans added on 2016-11-01 09:49:30:
Looks fine to me! Thanks, François!

I don't have a German keyboard either, confirmation that it fully works would be nice. If it still doesn't work with such a keyboard, please re-open!

fvogel added on 2016-10-30 13:56:48:

Test event-8 added, see [a766e47b6e].

Please review and comment. I didn't find a better way. The problem is how to distinguish a failing test from a successful test run a system having a keyboard without a physical diaeresis key.


fvogel added on 2016-10-30 11:46:37:
Tried it and it seems OK for me, but I don't have the german keyboard the OP probably has.

Could the OP please try the proposed fix and confirm?

Besides, we probably need a new test case for this bug, I will try to add one (assigning the ticket to myself for that purpose).

jan.nijtmans added on 2016-10-23 14:06:38:
Proposed fix committed to branch "bug-e36963bfe8". Still to be tested

fvogel added on 2016-10-12 11:02:51:
Indeed, casting to (unsigned char) instead of (char) makes the demo script behave again OK for me.

jan.nijtmans added on 2016-10-11 22:28:55:
The function VkKeyScan() has ASCII variants (VkKeyScanA) and wide (VkKeyScanW). This means that the cast to (char) is wrong, it should at least be (unsigned char). Otherwise the W variants of VkKeyScanW will map this character to a non-existing code point. That explains the difference in Tcl 8.5 and 8.6

Does changing the cast from (char) to (unsigned char) help? I'm not sure if that's the optimal solution, but I'll have a further look later.

Thanks, François, for identifying the function where it goes wrong! That surely helps!

fvogel added on 2016-10-05 08:23:22:
I don't think you can help more, thanks. I have identified below the commit that first created the issue and have prompted the person who made that commit. Unfortunately I'm not able to go further than this.

[email protected] added on 2016-10-05 07:36:18:
Hello!

Any news on this subject?
Can I support wit more information or tests to solve this bug?

Thanks
Matthias

fvogel added on 2016-08-04 21:04:38:
fossil bisect identifies the following commit as being the first one changing the result value (from 477 to -1, with  event generate .e <diaeresis> ) in
    result = VkKeyScan((char) keySym);
in tkWinkey.c:TkpSetKeycodeAndState()

BAD     2010-09-09 14:59:24 81ceafb7cffe33b5

[81ceafb7] win/rules.vc: (sync with tcl version) mingw should always link with -ladvapi32 Remove ascii variant of tkWinPocs table, it is no longer necessary. (user: nijtmans, tags: trunk) 

Jan, any input perhaps please?

fvogel added on 2016-08-04 15:01:57:
Thanks for this clear and detailed response.

So the problem lies:
  1. on Windows only
  2. in the development line between 8.5.14 and 8.6.1

Great! Now, in principle at least, we should be able to fossil bisect (and I will perhaps do that, but read below).

When calling  event generate .e <diaeresis>
the sequence of functions called is  HandleEventGenerate()  then  TkpSetKeycodeAndState()

On my computer/setup, TkpSetKeycodeAndState() receives 168 as keysym in both versions (8.5.14 and 8.6.1), which is the correct keysym (see  https://www.tcl.tk/man/tcl8.6/TkCmd/keysyms.htm )

The task of TkpSetKeycodeAndState() is to map a a keysym to a keycode plus modifiers. Everything happens identically in both Tk versions until the line:

    result = VkKeyScan((char) keySym);

is reached.

In 8.6.1, result receives -1
In 8.5.14, result receives a strictly positive value (477, IIRC)

So VkKeyScan(), which is a Windows API function, behaves differently in the two Tk versions. Why is this...?

[email protected] added on 2016-08-04 08:51:48:
Linux, Tk 8.6.1:  OK
Linux, Tk 8.6.4:  OK
Linux, Tk 8.5.14: OK


Windows, Tk 8.6.1  ERROR
Windows, Tk 8.6.4  ERROR
Windows, Tk 8.5.11 OK
Windows, Tk 8.5.14 OK


My Test-Script is
------
pack [entry .e]
bind .e <KeyPress> {puts "keypress %K %k"}

focus -force .e 
update; after 3000 {
   event generate .e <diaeresis>
   event generate .e <Udiaeresis>
   event generate .e <Adiaeresis>
}
------

On Linux th output is

8.6.1
after#0
keypress udiaeresis 34
keypress Udiaeresis 34
keypress Adiaeresis 48


8.6.4
after#0
keypress udiaeresis 34
keypress Udiaeresis 34
keypress Adiaeresis 48


8.5.14
after#0
keypress udiaeresis 34
keypress Udiaeresis 34
keypress Adiaeresis 48

and the entry-widget shows "üÜÄ"


On windows the output is

8.6.1
after#1
keypress ?? 0
keypress ?? 0
keypress ?? 0


8.6.4
after#1
keypress ?? 0
keypress ?? 0
keypress ?? 0

and the entry-widget is empty.


On Windows and tk 8.5.14 the output is

8.5.14
after#1
keypress ?? 0
keypress Udiaeresis 186
keypress Adiaeresis 222

and the entry-widget shows "ÜÄ" which is OK in my opinion.

Windows and Tk 8.5.11 is the same as 8.5.14

fvogel added on 2016-08-03 16:02:44:
To help narrowing the problem, could you please replace the question marks below by your observations:

- Windows, Tk 8.6.1 :  ?
- Windows, Tk 8.6.4 : OK
- Linux, Tk 8.6.1 : OK
- Linux, Tk 8.6.4 :  ?

This should all be checked on the very same hardware because mapping the platform-dependant keycode to a system-independent X keysym depends on the actual keyboard and keymap that Tk finds under its feet.

Thanks!

[email protected] added on 2016-08-02 06:51:08:
On Linux with 8.6.1:

% set tcl_patchLevel
8.6.1
% pack [entry .e]
% bind .e <KeyPress> {puts "keypress %K %k"}

The console  output is:

keypress adiaeresis 48
keypress udiaeresis 34
keypress odiaeresis 47


And with

focus -force .e 
update; after 3000 {
   event generate .e <diaeresis>
   event generate .e <Udiaeresis>
   event generate .e <Adiaeresis>
}

The console shows 

keypress udiaeresis 34
keypress Udiaeresis 34
keypress Adiaeresis 48

And the Entry-Widget shows
üÜÄ

fvogel added on 2016-07-31 18:26:51:
On Windows (Vista) with core-8-6-branch, running my test script I get the following results:

The entry widget shows nothing (the empty string).

And the console output is:

keypress ?? 0
keypress ?? 0
keypress ?? 0

fvogel added on 2016-07-31 18:23:44:
On Linux in 8.6.1 and 8.6.4 (and also in core-8-6-branch), after compiling these versions I get the same results for all of then, with the following test script:

     pack [entry .e]
     bind .e <KeyPress> {puts "keypress %K %k"}

     focus -force .e ; update

     after 3000 {
        event generate .e <diaeresis>
        event generate .e <Udiaeresis>
        event generate .e <Adiaeresis>
     }

The entry widget shows: (jq

And the console output is:

keypress parenleft 14
keypress j 44
keypress q 38

So it's strange that you report that it works for you with 8.6.1 on Linux.

fvogel added on 2016-07-29 20:55:03:

Duplicate of [222027] ?