Linux 通过 C 指针访问键盘
我是 C 新手,但不是编程新手。我想通过指针访问键盘按键。因为我已经尝试使用远指针并在 Windows 盒子上的 P2 系统中使用地址 0x417 和第 7 位进行编程。现在我想开始在 Linux 中工作并尝试使用相同的功能,但大写锁定没有任何反应。任何人都可以给我发送一些关于 Ubuntu Linux 中的硬件和文件属性访问的好教程。
我非常感谢你们大家。
问候,
I am new in C but not in programming. I want access keyboard keys through pointers. As I have tried it with far pointer and use the address 0x417 and 7th bit on with my programming in my P2 system on Windows box. Now I want to start working in Linux and trying to use the same function but nothing happen with caps lock. Any one can send me some good tutorial about the hardware and file attribute access in Ubuntu Linux.
I am very much thankful to you all.
Regards,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Linux 上您不能通过指针访问键盘。
如果您正在考虑图形应用程序,它使用 X11 及其底层协议(这是非常对于新手来说很复杂)。如果您是新手,我强烈建议您使用图形工具包库,例如 Qt 或 GTK。
如果您正在考虑控制台应用程序,我建议您使用类似 ncurses 或 < a href="http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html" rel="nofollow">阅读行。
您确实可以读取原始键盘(因为例如 Xorg 服务器可以读取原始键盘),但这很痛苦。您需要了解tty-s,而且细节很痛苦。您还需要了解原始 Linux 键盘(我忘记了详细信息,但请研究 Xorg 服务器以获取更多信息)。
你真的应该解释一下你想做什么。请注意,要完全详细地了解什么是 tty 或什么是原始键盘需要花费数月的时间。你应该熟悉 linux 系统调用甚至在开始之前。
您应该利用几乎所有 Linux 软件都是免费的优势;所以你可以研究它的源代码。
You don't access the keyboard thru pointers on Linux.
If you are thinking of a graphical application, it uses X11, and its underlying protocol (which is very complex for newbies). If you are a newbie, I strongly recommend using a graphical toolkit library like Qt or GTK.
If you are thinking of a console application, I do recommend using a library like ncurses or perhaps readline.
You could indeed read the raw keyboard (since e.g. the Xorg server does), but this is painful. You'll need to learn about tty-s and the details are painful. You'll also need to learn about the raw linux keyboard (I forgot the details, but study the Xorg server for more).
You really should explain what you want to do. Be aware that understanding in full detail what is a tty or what is the raw keyboard takes months of work. And you should be familiar with linux system calls before even starting.
You should take advantage that nearly all Linux software is free; so you can study its source code.
在 Ubuntu(或任何普通 Linux 发行版)上读取 Caps Lock 的最简单方法可能是使用 SDL 库,< a href="http://www.libsdl.org/docs/html/guideinputkeyboard.html" rel="nofollow">示例。
在 Ubuntu 上,您可以使用 apt-get install libsdl-dev 在命令行上安装该库。
The easiest way to read Caps Lock on Ubuntu (or any normal Linux distribution) is probably with the SDL library, example here.
On Ubuntu you would install that library on the command line with
apt-get install libsdl-dev
.