Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在Smalltalk Pharo 2中多次查看键盘事件_Smalltalk_Pharo - Fatal编程技术网

无法在Smalltalk Pharo 2中多次查看键盘事件

无法在Smalltalk Pharo 2中多次查看键盘事件,smalltalk,pharo,Smalltalk,Pharo,我想查看键盘事件,根据传感器文档,我可以使用peekKeyboardEvent在不从队列中删除事件的情况下执行此操作,但是它似乎不起作用 这项工作: "Show that a single event can be checked multiple times" Transcript clear; show: 'Type something... '; flush. (Delay forSeconds: 2) wait. 5 timesRepeat: [ Transcript sho

我想查看键盘事件,根据传感器文档,我可以使用peekKeyboardEvent在不从队列中删除事件的情况下执行此操作,但是它似乎不起作用

这项工作:

"Show that a single event can be checked multiple times"
Transcript clear; show: 'Type something... '; flush.
(Delay forSeconds: 2) wait.
5 timesRepeat: [  
    Transcript show: (Sensor peekEvent); cr
]
输出:

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)
Type something... #(2 48205144 97 0 0 97 0 1)
nil
nil
nil
nil
但这并不是:

"Show that a single keyboard event can be checked multiple times"
Transcript clear; show: 'Type something... '; flush.
(Delay forSeconds: 2) wait.
5 timesRepeat: [  
    Transcript show: (Sensor peekKeyboardEvent); cr
]
输出:

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)
Type something... #(2 48205144 97 0 0 97 0 1)
nil
nil
nil
nil

还有一个问题:为什么转录刷新不会导致输出立即出现?它只有在脚本运行后才会出现。

首先,pharo是一个移动速度很快的目标,因此最好知道哪个版本

找到答案的最佳方法是浏览代码。我将在当前开发的Pharo3.0中展示这一点 如果浏览peekKeyboardEvent的实现者,然后选择Alt+m,您将在InputEventSensor中找到一个版本:

peekKeyboardEvent
    "Allows for use of old Sensor protocol to get at the keyboard,
    as when running kbdTest or the InterpreterSimulator in Morphic"

    ^eventQueue findFirst: [:buf | self isKbdEvent: buf]
如果您分析对eventQueue的inst var引用

initialize
        "Initialize the receiver"
        super initialize.
        eventQueue := WaitfreeQueue new.
        ...snip...
然后浏览WaitfreeQueue选择它然后Alt+b

findFirst: aBlock
    "Note, this method only for backward compatibility. It duplicating the semantics of #nextOrNilSuchThat: completely.
    Use #nextOrNilSuchThat: instead "

    ^ self nextOrNilSuchThat: aBlock
然后:

您可以信任注释,也可以自己在代码中验证此方法是否正在使用事件而不是偷看


因此,这种投票方式似乎确实不受欢迎,并且在pharo中失去了支持

有趣的是,从阅读中可以看出,这些投票方法受到了强烈的反对,事件才是前进的方向。嗨,Aka,谢谢你的评论。我想我们当时都同意意见不一致。希望在Pharo3中,轮询将被删除,或者InputEventSensor中的方法将被清理,以便它们不会产生误导。