我想知道为什么以下代码不起作用:
object Main extends SimpleSwingApplication {
val dim = new Dimension(500, 110)
def top = new MainFrame {
contents = new FlowPanel{
listenTo(keys, mouse.clicks)
reactions += {
case MouseClicked(_,_,_,_,_) => println("Mouse clicked")
case KeyPressed(_, Key.C, _, _) => println("C pressed")
case KeyTyped(_, Key.C, _, _) => println("C typed")
case KeyReleased(_, Key.C, _, _) => println("C released")
}
}
size = dim
}
}
鼠标点击将被识别,但按键不会被识别。我还尝试了不同的键或修饰符,但似乎没有任何效果。我做错了什么?
(在不太可能的情况下,这可能与环境有关:我在 Windows 7 上使用 SBT 运行此代码)
最佳答案
关于scala - KeyEvent 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13677001/