I've been playing with creating a simple 2D asteroids type game in Squeak, and when it came time to try to monitor how long the accelerator key for the rocket (up arrow in this case) had been pressed, I ran into all sorts of oddities.
On an intel Mac OS X 10.6.8 box, running various Cog VMs, I found that the event passed to #keyDown: contained zero as the value, regardless of which key was pressed.
On Linux, this problem seems not to exist.
Again on the Mac, this test class http://paste.lisp.org/display/124816 doesn't seem to work.
I was trying to grab the raw Sensor event buffer, but I can't seem to get more than a handful of events.
#step is where the meat of the code is. It tries to grab events from Sensor and if they are keyboard events, put them into a buffer for examination.
You evoke the test morph thusly:
myMorph := MyMorph new. myMorph openInWorld. Transcript show: myMorph aCounter. Transcript show: myMorph eventBuffer.
Obviously, I'm doing something fundamentally wrong (or the MacOS X bug for #keyDown manifests directly with Sensor).
Help?
THanks
Lawson.
On 23.09.2011, at 12:15, Lawson English wrote:
I've been playing with creating a simple 2D asteroids type game in Squeak, and when it came time to try to monitor how long the accelerator key for the rocket (up arrow in this case) had been pressed, I ran into all sorts of oddities.
On an intel Mac OS X 10.6.8 box, running various Cog VMs, I found that the event passed to #keyDown: contained zero as the value, regardless of which key was pressed.
On Linux, this problem seems not to exist.
Again on the Mac, this test class http://paste.lisp.org/display/124816 doesn't seem to work.
I was trying to grab the raw Sensor event buffer, but I can't seem to get more than a handful of events.
#step is where the meat of the code is. It tries to grab events from Sensor and if they are keyboard events, put them into a buffer for examination.
You evoke the test morph thusly:
myMorph := MyMorph new. myMorph openInWorld. Transcript show: myMorph aCounter. Transcript show: myMorph eventBuffer.
Obviously, I'm doing something fundamentally wrong
Yes. Do Not Use Sensor Directly From Morphic Code. Otherwise you get unpredictable behavior because the Morphic main loop also fetches events from Sensor.
That said, keyboard events are indeed inconsistent across platforms, and you have to make do with whatever the particular platform offers. Be sure to look at both the 8-bit char code (evtBuf at: 3) and the 32 bit unicode (evtBuf at: 6) - some keys may be reported only in one of the two places. A good strategy is to look at (evtBuf at: 6) and if it is 0 use (evtBuf at: 3).
Note that on the Mac, keydown/up events use different codes than stroke events.
- Bert -
[This is a duplicate of what was sent in reply to the Dev list. It may be an image problem and it may be a VM problem so I'm sending to both places]
On 9/23/11 1:59 PM, Bert Freudenberg wrote:
On 23.09.2011, at 12:15, Lawson English wrote: [...]
Obviously, I'm doing something fundamentally wrong
Yes. Do Not Use Sensor Directly From Morphic Code. Otherwise you get unpredictable behavior because the Morphic main loop also fetches events from Sensor.
That said, keyboard events are indeed inconsistent across platforms, and you have to make do with whatever the particular platform offers. Be sure to look at both the 8-bit char code (evtBuf at: 3) and the 32 bit unicode (evtBuf at: 6) - some keys may be reported only in one of the two places. A good strategy is to look at (evtBuf at: 6) and if it is 0 use (evtBuf at: 3).
Note that on the Mac, keydown/up events use different codes than stroke events.
- Bert -
That's the thing. Here are the variables from doing "evt inspect" from within #keyDown: and #keyStroke. Notice that the keyValue info is missing, period, from the event passed into #keyDown: That is why I was trying to "roll my own". Linux doesn't have this problem, but the Mac does. I beat my head against this wall all night, stepping through the debugger trying to find out where things went wrong.
timeStamp: 379995 source: a HandMorph(3216) type: #keystroke buttons: 0 position: 114@237 handler: nil wasHandled: true keyValue: 102
timeStamp: 379995 source: a HandMorph(3216) type: #keyDown buttons: 0 position: 114@237 handler: nil wasHandled: true keyValue: 0
vm-dev@lists.squeakfoundation.org