#include #include #include int keys[] = { Qt::Key_Z, /* prev wep */ Qt::Key_X, /* next wep */ Qt::Key_Space, /* shoot */ Qt::Key_Up, Qt::Key_Left, Qt::Key_Down, Qt::Key_Right, Qt::Key_P, Qt::Key_Backspace, }; std::string key_names[] = { "Z", "X", "Space", "Up", "Left", "Down", "Right", "Pause", "Backspace", }; #define ARRAY_SIZE(a) (sizeof (a) / sizeof *(a) ) class Application: public QApplication { public: Application(int & argc, char **argv): QApplication(argc, argv) { setbuf(stdout, NULL); /* disable buffering */ } ~Application(){} bool notify(QObject *object, QEvent *event) { bool is_pressed = event->type() == QEvent::KeyPress; if (is_pressed || event->type() == QEvent::KeyRelease) { if (handle_key(static_cast(event)->key(), is_pressed)) return true; } return object->event(event); } private: bool handle_key(int code, bool is_pressed) { for (unsigned int i=0; i= 300; if (last_code == key && !always_send_key(key)) { if ((is_pressed == last_is_pressed) || (last_is_pressed && !is_pressed)) { //if (!timed_out) { return; //} } } else { if (!always_send_key(last_code)) release_key(); } last_code = key; last_is_pressed = is_pressed; //last_time = timestamp; send_key(key, is_pressed); } void send_key(int key, bool is_pressed) { printf("%u %u\n", key, is_pressed); if (is_pressed) std::cerr << key_names[key - 1] << " " << (is_pressed ? "pressed" : "released") << std::endl; } }; int main(int argc, char **argv) { Application app(argc, argv); QWidget window; window.resize(250, 150); window.setWindowTitle("Remote keyboard"); window.show(); return app.exec(); }