使用下面看看鏈接的函數void kGUISystemX ::環路(無效)
這是我在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);
......
我覺得這個問題很廣泛。直接與輸入設備交談? (通常對於高級應用程序來說是一個壞主意。)使用X? (如果X,控制檯模式下的鼠標需要Xlib,XCB,Gtk +,Qt,...)GPM嗎? – asveikau 2012-12-24 01:42:38