[Newbies] Detecting keyboard state / finding older fixes
stan shepherd
squeak414 at free.fr
Fri Mar 7 13:54:10 UTC 2008
Where I was confused is that checking if the key is pressed already doesn't
appear to differentiate between a 'real' key down and a repeat. For example
:
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?
On the other hand, looping over this in a thread:
keyStrokes
keys
do: [:key | key
ifNotNil: [(oldKeys includes: key)
ifFalse: [Transcript show: 'key added ' , key asString;
cr]]].
oldKeys do: [:key | key
ifNotNil: [(keys includes: key)
ifFalse: [Transcript show: 'key removed ' , key asString;
cr]]].
oldKeys := keys copy.
has the desired effect of only showing real key moves.
Is this over complicating things?
...Stan
Bert Freudenberg wrote:
>
> Assuming this is for a game, you would effectively prevent someone
> "hammering" on a key to do some action repeatedly. Also this depends
> on the actual repeat rate which varies widely between systems. In my
> example there is no such fixed timeout, you simply would check if the
> key is pressed already (i.e. it is in the keys set).
>
> - Bert -
>
>
>
--
View this message in context: http://www.nabble.com/Detecting-keyboard-state---finding-older-fixes-tp15779144p15891252.html
Sent from the Squeak - Beginners mailing list archive at Nabble.com.
More information about the Beginners
mailing list