Key values in Tweak platform-dependend?

John M McIntosh johnmci at smalltalkconsulting.com
Sun Jan 21 19:21:21 UTC 2007


Well the VM's generate key down, key char and key up.  with repeating  
doing some odd dance according to what Windows thinks should be done.

Morphic considers a certain event and pulls data from it to  
distribute the keyboard events, you've likely noted which events  
morphic triggers on for keyboard input
is different from Tweak which considers a different set of events.

The macintosh carbon VM based on wishes from the tweak developers  
many years back resolved to.

        /* Put the sqKeyboardEvent for KeyDown */
		enterKeystroke ( EventTypeKeyboard, macKeyCode, EventKeyDown, 0,  
modifierBits);

Where macKeyCode is the magic number that matches to a key on the  
keyboard. Windows VM's I understand use a different magic number  
signalling the "A" key
was pressed.
For windows look at the virtual key codes http://msdn2.microsoft.com/ 
en-us/library/ms645540.aspx
For macintosh look at http://developer.apple.com/documentation/mac/ 
Text/Text-571.html#MARKER-9-18
		
         /* generate extra character event */
		enterKeystroke ( EventTypeKeyboard, macRomanCode, EventKeyChar,  
modifiedUniChar, modifierBits);

The mac vm for historical reasons returns a mapped MacRoman value as  
the key down, plus the Unicode value. It's possible that the MacRoman  
value will be zero.
I believe the windows vm also returns the macRomanCode for historical  
reasons to preserve the logic for high ascii mapping in 1996...

     /* Put the sqKeyboardEvent for KeyUp */
		if (!ISawRawKeyRepeat && (uniCharCount> 1 || (keyIndex < 0)))
			enterKeystroke ( EventTypeKeyboard, macKeyCode, EventKeyUp, 0,   
modifierBits);



I had wanted to supply the unicode value for keyDown and keyUp  
because on some combinations of dead keys in Europe it is possible  
not to be able to determine
exactly what the key code is/was, or should be. However the tweak vm  
developers said it was impossible for Windows to provide that  
information at key up/down time so no changes were done. However  
users in Europe will find it's impossible to enter some clever  
keystroke combination via a Windows VM...


In Sophie we have a lookup table based on platform to provide the  
mapping to ascii

macintosh>>cursorKeys
	"Answer the default cursor keys to be used on this platform"
	^self macVirtualKeycodes
		ifFalse: [super cursorKeys]
		ifTrue: [#(
			((123) moveCursorLeft)
			((124) moveCursorRight)
			((126) moveLineUp)
			((125) moveLineDown)
			((115) moveLineStart)
			((119) moveLineEnd)
			((116) movePageUp)
			((121) movePageDown)
			((shift 123) selectCursorLeft)
			((shift 124) selectCursorRight)
			((shift 126) selectLineUp)
			((shift 125) selectLineDown)
			((shift 115) selectLineStart)
			((shift 119) selectLineEnd)
			((opt 123) moveWordLeft)
			((opt 124) moveWordRight)
			((ctrl 123) moveWordLeft)
			((ctrl 124) moveWordRight)
			((cmd 123) moveWordLeft)	"should be move line start?"
			((cmd 124) moveWordRight)	"should be move line end?"
			((ctrl 126) scrollLineUp)
			((ctrl 125) scrollLineDown)
			((cmd 115) moveTextStart)
			((cmd 119) moveTextEnd)
			((ctrl 115) moveTextStart)
			((ctrl 119) moveTextEnd)
			((opt 115) moveTextStart)
			((opt 119) moveTextEnd)
			((cmd shift 123) selectWordLeft)
			((cmd shift 124) selectWordRight)
			((opt shift 123) selectWordLeft)
			((opt shift 124) selectWordRight)
			((cmd shift 115) selectTextStart)
			((cmd shift 119) selectTextEnd)
			((opt shift 115) selectTextStart)
			((opt shift 119) selectTextEnd)
			((ctrl shift 115) selectTextStart)
			((ctrl shift 119) selectTextEnd)
	).]



windows>>cursorKeys
	"The standard cursor keys"   "HAH I wonder if all the keystrokes are  
here,   "
	^#(
			((28) moveCursorLeft)
			((29) moveCursorRight)
			((30) moveLineUp)
			((31) moveLineDown)
			((1) moveLineStart)
			((4) moveLineEnd)
			((11) movePageUp)
			((12) movePageDown)
			((shift 28) selectCursorLeft)
			((shift 29) selectCursorRight)
			((shift 30) selectLineUp)
			((shift 31) selectLineDown)
			((shift 1) selectLineStart)
			((shift 4) selectLineEnd)
			((ctrl 28) moveWordLeft)
			((ctrl 29) moveWordRight)
			((ctrl 30) scrollLineUp)
			((ctrl 31) scrollLineDown)
			((ctrl 1) moveTextStart)
			((ctrl 4) moveTextEnd)
			((ctrl shift 28) selectWordLeft)
			((ctrl shift 29) selectWordRight)
			"((ctrl shift 30) ---)
			((ctrl shift 31) ---)"
			((ctrl shift 1) selectTextStart)
			((ctrl shift 4) selectTextEnd)
	).



On Jan 21, 2007, at 7:58 AM, Stefan wrote:

> Hi folks,
>
> We are 3 students trying to implement a lil' game in Tweak. In  
> doing so, we have to catch keyboard events using a method like:
>
> onKeyDown: event
>    | keyValue |
>    <on: keyDown>
>    keyValue := event keyValue.
>    Thereby the value of keyValue differs in dependency of the  
> underlying OS. On Windows the keyValue equals the ASCII-values ('A'  
> = 65). On Mac OS we get completely different values, e.g., an 'A'  
> results in 0.
>
> Currently we work around that problem by checking Smalltalk  
> platformName. Does someone know another (and better ;) ) way to  
> resolve it?
>
> Thanks for your help.
>

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





More information about the Squeak-dev mailing list