erlang 如何捕获击键?

toe95027  于 2022-12-08  发布在  Erlang
关注(0)|答案(2)|浏览(139)

我想做一个简单的Erlang控制台游戏。我需要控制我的"车"在游戏中的关键击键-键向上或W键。有没有办法做到这一点?我读到wx库有这样的能力,但我正在寻找一些简单的东西,在我看来wx库是矫枉过正。我想抓住一个事件,而不是字符从stdin。
编辑:
好的,我选择了ncurses和cecho作为Erlang库。

iaqfqrcu

iaqfqrcu1#

I know only 2 way to do this: gs and wx.
gs is a bit simpler but the first line of the documentation is a warning telling that gs is not recommended for new application, use wx instead :o)
wx isn't so complex, but its documentation is really poor, and simply refers to wxWidget one. at least there are some demo (demo, sudoku, xrc...) that helps to start to build something. And once you succeed to have your first panels and sizers working, it is really simple to get the key stroke or mouse events an react on them. My main difficulty was in displaying graphical things fast and smooth enough even if at the end it is only a few lines of code (a few 10s).
finally, the erlang console is meant to evaluate erlang expression, so there is no chance that you can capture simple event and control the display in that environment (at a reasonable effort at least).

56lgkhnf

56lgkhnf2#

您可以尝试学习kernel的模块groupuser_drv,但它们都有未公开的接口,并且可能在任何未来的Erlang/OPT版本中发生变化。您也可以制作自己的驱动程序或NIF来处理termios设置,并制作自己的实现。
顺便说一句,我肯定会坚持使用wx

相关问题