Linux的键盘原始读数,更棒的是,从/ dev /输入/ EVENT0读取或从标准输入读取? [英] Linux keyboard raw reading, what's better, reading from /dev/input/event0 or reading from stdin?

查看:2322
本文介绍了Linux的键盘原始读数,更棒的是,从/ dev /输入/ EVENT0读取或从标准输入读取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个小的C库电子游戏为树莓派。我从头开始编码输入系统和阅读,看到大约原始输入读一些例子后,我得到了一些疑问。

I'm working on a small C videogames library for the Raspberry Pi. I'm coding the input system from scratch and after reading and seeing some examples about raw input reading, I got some doubts.

有关鼠标的阅读,我只是使用/ dev /输入/ EVENT1,我打开()作为O_NONBLOCK,我阅读()input_event(S),我也把鼠标读数在一个单独的pthread。很简单。

For mouse reading, I just use /dev/input/event1, I open() it as O_NONBLOCK, I read() input_event(s) and I also put the mouse reading in a separate pthread. Easy.

有关键盘的阅读,我看到一些例子来重新配置标准输入到O_NONBLOCK(使用的fcntl()),然后保存并重新配置键盘的termios attibutes(ICANON,ECHO)和一些例子也保存和重新配置键盘模式的ioctl()。什么是做所有的东西,而不是仅仅读的/ dev /输入/ EVENT0 input_event(S)(相同的方式,鼠标)?

For keyboard reading, I saw some examples that reconfigure stdin to O_NONBLOCK (using fcntl()), then save and reconfigure keyboard termios attibutes (ICANON, ECHO), and some example also save and reconfigure keyboard mode with ioctl(). What's the point of doing all that stuff instead of just reading /dev/input/event0 input_event(s) (same way as mouse)?

请注意,我已了解了这些功能做的,我只是不为什么已了解应该更好地做所有的东西,而不是仅仅读input_event(S)。

Note that I undestand what those functions do, I just don't undestand why should be better to do all that stuff instead of just reading input_event(s).

推荐答案

阅读标准输入并不仅限于阅读本地连接的键盘(但还有其他的局限,使大多不适合游戏)。然后读取标准输入,你可以从远程登录用户使用本地连接串行终端或终端仿真器(可能是从远程X服务器操作)来读取按键。

Reading stdin is not limited to reading locally connected keyboards (but has other limitation making it mostly unsuitable for games). Then reading stdin you could be reading keystrokes from a user logged in remotely, using a locally connected serial terminal or a terminal emulator (possibly operated from a remote X server).

有关基于终端的游戏中,它可能是有意义的使用标准输入。但它可能会更好地使用 GPM ,而不是阅读的/ dev /输入/ EVENT1为鼠标。甚至可能更好地使用 ncurses的的一切。

For terminal based games it might make sense to use stdin. But then it would probably be better to use GPM instead of reading /dev/input/event1 for the mouse. And possibly even better to use ncurses for everything.

否则,你可能想看看 SDL ,如果​​不是直接使用它,至少学习不同的方式来读取输入。例如,SDL拥有十,使用这意味着游戏可以执行一台计算机上,但在另一个播放网络透明的全力支持。

Otherwise you might want to look at SDL, if not for using it directly, at least for learning about different ways to read input. For example, SDL has full support for network transparency using X. Which means a game can execute on one computer but be played on another.

这篇关于Linux的键盘原始读数,更棒的是,从/ dev /输入/ EVENT0读取或从标准输入读取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆