[Newbies] Detecting keyboard state / finding older fixes
bert at freudenbergs.de
Fri Mar 7 14:30:57 UTC 2008
On Mar 7, 2008, at 14:54 , stan shepherd wrote:
> Where I was confused is that checking if the key is pressed already
> appear to differentiate between a 'real' key down and a repeat. For
> keyDown: anEvent
> (keys includes: anEvent keyValue)
> ifTrue: [Transcript show: 'skipped ' , anEvent asString; cr]
> ifFalse: [keys add: anEvent keyValue. "
> Transcript show: 'key down ' , anEvent asString; cr.
> self changed]
> always takes the 'key down' branch, even for key held down.
> Was this what you meant?
Yes. The code above works as expected on Mac OS X, printing
"skipped..." for auto-repeats.
> On the other hand, looping over this in a thread:
> do: [:key | key
> ifNotNil: [(oldKeys includes: key)
> ifFalse: [Transcript show: 'key added ' , key asString;
> oldKeys do: [:key | key
> ifNotNil: [(keys includes: key)
> ifFalse: [Transcript show: 'key removed ' , key asString;
> oldKeys := keys copy.
> has the desired effect of only showing real key moves.
> Is this over complicating things?
It indeed sounds overly complicated, unless your platform forces you
to resort to such things. Are you on Linux by chance?
- Bert -
More information about the Beginners