我正在Linux下開發一個使用Qt 4.8的3D應用程序。現在我需要支持3D鼠標(3Dconnexion SpaceNavigator)。隨附的SDK相當老派,使用X11來檢索事件。使用Qt 4.8和Linux無法從3Dconnexion SpaceNavigator獲取事件
我使用SDK提供的示例代碼,並試圖將它與Qt 4.8結合使用。它看起來像設置鼠標正在工作(據我可以告訴從調試輸出),但我沒有得到與QWidget :: x11Event(XEvent *)的任何XEvent。
我已經找到解決方案規避使用libudev或libusb的SDK中,這兩者都是目前不適用於我:/
也許有人已經解決這個具體的問題?使用X11我無法想象現在所有人都:)
繼承人我使用Qt的設置代碼,調試輸出看起來像它的工作:
Display* pDisplay = QX11Info::display();
Atom event_motion = XInternAtom(pDisplay, "MotionEvent", TRUE);
Atom event_press = XInternAtom(pDisplay, "ButtonPressEvent", TRUE);
Atom event_release = XInternAtom(pDisplay, "ButtonReleaseEvent", TRUE);
Atom event_command = XInternAtom(pDisplay, "CommandEvent", TRUE);
std::cout << "MotionEvent: " << event_motion << std::endl;
std::cout << "ButtonPressEvent: " << event_press << std::endl;
std::cout << "ButtonReleaseEvent: " << event_release << std::endl;
std::cout << "CommandEvent: " << event_command << std::endl;
Atom ActualType;
int ActualFormat;
unsigned long NItems, BytesReturn;
Window root = RootWindow(pDisplay, DefaultScreen(pDisplay));
std::cout << "root: " << std::hex << "0x" << root << std::dec << std::endl;
unsigned char* p_property;
Window app_window = (Window) this->window()->winId();
XGetWindowProperty(pDisplay, root, event_command, 0, 1, FALSE,
AnyPropertyType, &ActualType, &ActualFormat, &NItems, &BytesReturn, &p_property);
if (0!=p_property)
{
Window wnd = *(Window*) p_property;
XFree(p_property);
std::cout << "magellan window number: " << std::hex << wnd << std::dec << std::endl;
XTextProperty wnd_name;
XGetWMName(pDisplay, wnd, &wnd_name);
std::cout << "magellan window name: " << wnd_name.value << std::endl;
XGetWMName(pDisplay, app_window, &wnd_name);
std::cout << "Found window property: " << wnd_name.value << " (" << std::hex << app_window << std::dec << ")" << std::endl;
XEvent CommandMessage;
CommandMessage.type = ClientMessage;
CommandMessage.xclient.format = 16;
CommandMessage.xclient.send_event = FALSE;
CommandMessage.xclient.display = pDisplay;
CommandMessage.xclient.window = wnd;
CommandMessage.xclient.message_type = event_command;
CommandMessage.xclient.data.s[0] = (short) XHigh32(app_window);
CommandMessage.xclient.data.s[1] = (short) XLow32(app_window);
CommandMessage.xclient.data.s[2] = 27695;
if (0!=XSendEvent(pDisplay, wnd, FALSE, 0x0000, &CommandMessage))
{
std::cout << "Sent event to SpaceMouse" << std::endl;
}
XSelectInput(pDisplay, app_window, NoEventMask);
}
感謝任何提示:)
正如一個側面說明:SpaceNavigator 3D鼠標本身確實工作,所以司機等正在運行。 – pettersson
[This](http://spacenav.sourceforge.net/)可能有些用處。過去我使用過類似的代碼。 –