首先,是的,我知道 this question ,但我正在寻找更多信息。实际上,我有一个非常相似的问题,因为我需要能够捕获鼠标/键盘/操纵杆的输入,而且我也想尽可能避免使用 SDL。我或多或少想知道是否有人知道我可以从哪里获得一些关于在 Linux 中处理来自设备的输入的入门读物,甚至可能是一些教程。 SDL 非常适合跨平台输入处理,但我根本不会使用 SDL 中的任何其他内容,因此我想将其完全删除。建议、评论和帮助都值得赞赏。谢谢!
为清楚起见编辑:
重点是捕捉游戏的鼠标 Action 、键盘按下/释放、鼠标点击和潜在的操纵杆操作。
最佳答案
使用下面的链接查看函数 void kGUISystemX::Loop(void)
这是我在 Linux 上使用 X Windows 通过键盘和鼠标获取输入的主循环。
http://code.google.com/p/kgui/source/browse/trunk/kguilinux.cpp
这是一个片段:
if(XPending(m_display))
{
XNextEvent(m_display, &m_e);
switch(m_e.type)
{
case MotionNotify:
m_mousex=m_e.xmotion.x;
m_mousey=m_e.xmotion.y;
break;
case ButtonPress:
switch(m_e.xbutton.button)
{
case Button1:
m_mouseleft=true;
break;
case Button3:
m_mouseright=true;
break;
case Button4:/* middle mouse wheel moved */
m_mousewheel=1;
break;
case Button5:/* middle mouse wheel moved */
m_mousewheel=-1;
break;
}
break;
case ButtonRelease:
switch(m_e.xbutton.button)
{
case Button1:
m_mouseleft=false;
break;
case Button3:
m_mouseright=false;
break;
}
break;
case KeyPress:
{
XKeyEvent *ke;
int ks;
int key;
ke=&m_e.xkey;
kGUI::SetKeyShift((ke->state&ShiftMask)!=0);
kGUI::SetKeyControl((ke->state&ControlMask)!=0);
ks=XLookupKeysym(ke,(ke->state&ShiftMask)?1:0);
......
关于c++ - 在 Linux 中捕获输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/125806/