[Pharo-project] [Event related] [Unix] Input event Sensor key decoding
Hi! I was looking why alt and ctrl keys behave the same in unix, jeje, so I looked at the vm and everything seemed to be alright, but in the image I always had *Cmd+a key* when doing *alt+akey* :S. And this is pretty annoying since it limits the ammount of shortcuts I can work with, and I also make things work different than the rest of the OS. So, searching I found a *KeyDecodeTable *in InputEventSensor, which was built with this method: installDuplicateKeyEntryFor: c | key | key := c asInteger. "first do control->alt key" KeyDecodeTable at: { key bitAnd: 16r9F . 2 } put: { key . 8 }. "then alt->alt key" KeyDecodeTable at: { key . 8 } put: { key . 8 } So, every character keypress that had a 2 as a modifier (a control) is converted as a command in here: processEvent: evt "Process a single event. This method is run at high priority." | type | type := evt at: 1. "Treat menu events first" type = EventTypeMenu ifTrue: [ self processMenuEvent: evt. ^nil]. "Tackle mouse events first" type = EventTypeMouse ifTrue: [ "Transmogrify the button state according to the platform's button map definition" evt at: 5 put: (ButtonDecodeTable at: (evt at: 5) + 1). "Map the mouse buttons depending on modifiers" evt at: 5 put: (self mapButtons: (evt at: 5) modifiers: (evt at: 6)). "Update state for polling calls" mousePosition := (evt at: 3) @ (evt at: 4). modifiers := evt at: 6. mouseButtons := evt at: 5. ^evt]. "Finally keyboard" type = EventTypeKeyboard ifTrue: [ * "Sswap ctrl/alt keys if neeeded" KeyDecodeTable at: {evt at: 3. evt at: 5} ifPresent: [:a | evt at: 3 put: a first; at: 5 put: a second]. * "Update state for polling calls" modifiers := evt at: 5. ^evt]. "Handle all events other than Keyborad or Mouse." ^evt. Now, I think this hack is there to allow the same behavior cross platform, but it is very ugly :( And bring a lot of UI limitations to the people who only have alt and ctrl and no Cmd button :P... Ok, removing this ugly code made my shortcuts work now with only with alt (cmd to the vm) and not with control, hehe, but I think that to fix things we have to clean them first :). Does anyone know the reason of the existance of this table (besides cross platform hacking)? Is this really useful? Can it be removed? Do I open a ticket? Guille
I would like to hear what others think because BTW in the eventModel package we moved part of this code to the keyboard event. Stef On Jan 25, 2012, at 9:59 PM, Guillermo Polito wrote:
Hi!
I was looking why alt and ctrl keys behave the same in unix, jeje, so I looked at the vm and everything seemed to be alright, but in the image I always had Cmd+a key when doing alt+akey :S. And this is pretty annoying since it limits the ammount of shortcuts I can work with, and I also make things work different than the rest of the OS.
So, searching I found a KeyDecodeTable in InputEventSensor, which was built with this method:
installDuplicateKeyEntryFor: c | key | key := c asInteger. "first do control->alt key" KeyDecodeTable at: { key bitAnd: 16r9F . 2 } put: { key . 8 }. "then alt->alt key" KeyDecodeTable at: { key . 8 } put: { key . 8 }
So, every character keypress that had a 2 as a modifier (a control) is converted as a command in here:
processEvent: evt "Process a single event. This method is run at high priority." | type |
type := evt at: 1.
"Treat menu events first" type = EventTypeMenu ifTrue: [ self processMenuEvent: evt. ^nil].
"Tackle mouse events first" type = EventTypeMouse ifTrue: [ "Transmogrify the button state according to the platform's button map definition" evt at: 5 put: (ButtonDecodeTable at: (evt at: 5) + 1). "Map the mouse buttons depending on modifiers" evt at: 5 put: (self mapButtons: (evt at: 5) modifiers: (evt at: 6)).
"Update state for polling calls" mousePosition := (evt at: 3) @ (evt at: 4). modifiers := evt at: 6. mouseButtons := evt at: 5.
^evt].
"Finally keyboard" type = EventTypeKeyboard ifTrue: [ "Sswap ctrl/alt keys if neeeded" KeyDecodeTable at: {evt at: 3. evt at: 5} ifPresent: [:a | evt at: 3 put: a first; at: 5 put: a second].
"Update state for polling calls" modifiers := evt at: 5. ^evt].
"Handle all events other than Keyborad or Mouse." ^evt.
Now, I think this hack is there to allow the same behavior cross platform, but it is very ugly :( And bring a lot of UI limitations to the people who only have alt and ctrl and no Cmd button :P... Ok, removing this ugly code made my shortcuts work now with only with alt (cmd to the vm) and not with control, hehe, but I think that to fix things we have to clean them first :).
Does anyone know the reason of the existance of this table (besides cross platform hacking)? Is this really useful? Can it be removed? Do I open a ticket?
Guille
participants (2)
-
Guillermo Polito -
Stéphane Ducasse