i want peek @ keyboard events, , according docs sensor
can without removing event queue peekkeyboardevent
, doesn't seem work.
this works:
"show single event can checked multiple times" transcript clear; show: 'type something... '; flush. (delay forseconds: 2) wait. 5 timesrepeat: [ transcript show: (sensor peekevent); cr ]
output:
type something... #(2 48243801 5 2 8 0 0 1) #(2 48243801 5 2 8 0 0 1) #(2 48243801 5 2 8 0 0 1) #(2 48243801 5 2 8 0 0 1) #(2 48243801 5 2 8 0 0 1)
but doesn't:
"show single keyboard event can checked multiple times" transcript clear; show: 'type something... '; flush. (delay forseconds: 2) wait. 5 timesrepeat: [ transcript show: (sensor peekkeyboardevent); cr ]
output:
type something... #(2 48205144 97 0 0 97 0 1) nil nil nil nil
a further question: why doesn't transcript flush
cause output appear instantly? appears after script has run.
first thing, pharo target moving fast, it's better tell version.
the best way find answer browse code. i'll show in current development pharo 3.0
if browse implementors of peekkeyboardevent (select alt+m), find version in inputeventsensor:
peekkeyboardevent "allows use of old sensor protocol @ keyboard, when running kbdtest or interpretersimulator in morphic" ^eventqueue findfirst: [:buf | self iskbdevent: buf]
if analyze inst var references eventqueue
initialize "initialize receiver" super initialize. eventqueue := waitfreequeue new. ...snip...
then browse waitfreequeue (select alt+b)
findfirst: ablock "note, method backward compatibility. duplicating semantics of #nextornilsuchthat: completely. use #nextornilsuchthat: instead " ^ self nextornilsuchthat: ablock
then:
nextornilsuchthat: ablock "fetch object queue satisfies ablock, skipping (but not removing) intermediate objects. if no object has been found, answer <nil> , leave me intact. nota bene: ablock can contain non-local return (^). found item removed queue . if queue in middle of extraction other process, don't wait , return <nil> immediately" ...snip...
you can trust comment, or verify in code, method consuming event rather peeking.
so seems indeed polling style deprecated , loosing support in pharo
Comments
Post a Comment