[Newbies] Detecting keyboard state / finding older fixes

stan shepherd squeak414 at free.fr
Wed Mar 5 17:46:40 UTC 2008

Bert, Thanks for the reply and example.

To get around the repeat key issue, I'm testing the elapsed time since last
keystroke. If it's too short, assume it's repeat key from the OS:

	keyDelay := 	(anEvent timeStamp) - (lastEventTime at: noteNo) .
	lastEventTime at: noteNo put: anEvent timeStamp.
	(keyDelay < 250) ifTrue: [		"Transcript show: 'key repeat ignored'; cr."
				^self].    "assume it's a key repeat'"

p.s. I'm sure there is a 'Squeakier' way to do this.

Bert Freudenberg wrote:
> On Mar 4, 2008, at 19:19 , stan shepherd wrote:
>> handleKeyUp: anEvent
>> 	Transcript show: ' evt is down ',anEvent isKeyDown asString; cr.
>>         "now press and hold a key"
>> shows
>>  evt is down false
> Which is of course expected since only keyUp events are passed into  
> #handleKeyUp:, so #isKeyDown always is false.
> You need to handle both keyDown and keyUp events, and track the state  
> of pressed keys.
> Note that the keyValue in up/down events is system-specific (unlike  
> keyStroke events which have actual characters).
> Also note that this behavior also depends on your OS and VM version.  
> The Windows VM handles up/down events nicely for a long time, Mac VMs  
> since recently, Unix VMs are broken I think.
> I'm attaching a small example morph demonstrating this.
> - Bert -
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

View this message in context: http://www.nabble.com/Detecting-keyboard-state---finding-older-fixes-tp15779144p15855607.html
Sent from the Squeak - Beginners mailing list archive at Nabble.com.

More information about the Beginners mailing list