Mac Keyboard Events (was: Which version of image ?)

John M McIntosh johnmci at smalltalkconsulting.com
Thu Oct 27 17:47:52 UTC 2005


On 27-Oct-05, at 7:53 AM, Bert Freudenberg wrote:

> I added this output to HandMorph>>generateKeyboardEvent:


>
> Transcript
>     show: type; space;
>     show: evtBuf third asString; space;
>     show: evtBuf sixth asString; cr.
>
> So this should show the type, char code, and the unicode.
>
> "s"
> keyDown 1 1
> keystroke 115 115
> keyUp 1 1

I'll note that only keystroke generates a UniCode Event, the '1' here  
for the unicode value for down/up is bogus. It is reusing a circular  
set of buffers so it's picking up what the unicode value was in the  
far past. I have changed the code to set the unicode to zero on key  
up/down.

>
> "ß"
> keyDown 1 0
> keystroke 167 223
> keyUp 1 0
>
> "ú = Option-e u (dead key)"
> keyUp 14 0
> keyDown 32 13
> keystroke 156 250
> keyUp 32 0

Part of the problem here is that keyboard events are turned into  
keystrokes by language services.  Which means problems with dead keys  
since the generated keystrokes won't follow until the entire key up/ 
down sequence is entered, however since we are looking at key up/down  
that will generate the key up for dead keys before the computed  
keystroke.
For some reason we don't generate (on purpose based on past  
discussions about tweak I"d guess) keydowns for dead keys.

#(2 165764821 14 2 0 0 0 1)  Raw Event in EventSensor
2 14 0  {e key goes up)  reported by raw keyboard watcher, we don't  
report the e key down.

At this point then entering of the 'u' key generates a computed  
accented 'u' which then generates the next three events.
We did not actually record the key down/up sequence at the time it  
happened, otherwise you would see
e key goes up, u key goes down, u key goes up, ú is keystroke. We  
arrange things so you seem to see
key down, keystroke, key up.

#(2 165769030 32 1 0 0 0 1)Raw Event in EventSensor
1 32 0  {u key goes down}

#(2 165769030 156 0 0 250 0 1)Raw Event in EventSensor
0 156 250  {computed keystroke is ascii 156, or unicode 250 according  
to language services}

#(2 165769140 32 2 0 0 0 1)Raw Event in EventSensor
2 32 0 {u key goes up}

Also see
http://developer.apple.com/documentation/mac/Text/ 
Text-571.html#MARKER-9-18
to decode keyboard virtual codes.


>
> "left arrow"
> keyDown 124 0
> keystroke 29 29
> keyUp 124 0
>
> "s"
> keyDown 1 0
> keystroke 115 115
> keyUp 1 0
>
> "F1"
> keyDown 122 0
> keystroke 16 16
> keyUp 122 0
>
> "F2"
> keyDown 120 0
> keystroke 16 16
> keyUp 120 0
>
>
> My findings:
>
> - charCode in stroke events is MacRoman
Correct

> - charCode in up/down events is virtual keycodes
Correct

> - utf32Code in stroke events is Unicode, except for non-printable  
> keys, where it uses MacRoman
Correct, operating system gives back zero sometimes, we stick  
MacRoman in there.

> - utf32Code in up/down events is something I don't get.
Bogus.

> - there is an "up" event before the down event in the option-e dead  
> key sequence
See explaination above.

> - the two "s" down/ups differ in the utf32Code
Bogus values, fixed in next version will set to zero.

> - all "F#" keys have the same stroke value
Ya, for some reason F# Generate ascii 16, well that is all we get  
from the operating system.
.

> - there are no up/down events for modifier keys
State changes for modifier keys generate a mouse move event. If at  
any time you ask for the state of the modifier keys, EvevntSensor  
will correctly answer what state the keys are in. I could keep an  
internal table of the state of the modifier keys and generate key up/ 
down events, but that is a hassle I've been avoiding, so you have a  
good reason?  Mind one could in theory generate keyboard events in  
squeak when they see the modifier state change on a mouse event. That  
would be better since it would then work for all past VMs. Just poke  
at EventSensor, or Morphic/Tweak for mac carbon based VMs.

>
>
> - Bert

For fun, see what the Unix VM generates, the original code for dead  
key keystroke logic came from there.


--
======================================================================== 
===
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
======================================================================== 
===




More information about the Squeak-dev mailing list