bool CentralWidget::linuxEventFilter(QEvent *event) { QKeyEvent *keyEvent = dynamic_cast< QKeyEvent * >(event); if (event->type() == QEvent::KeyPress) { int key = keyEvent->key(); switch (key) { case Qt::Key_Up: joystick->setUpButtonPressed(true); keyPress(key, &CentralWidget::slotCarDirectCmd); return true; case Qt::Key_Down: joystick->setDownButtonPressed(true); keyPress(key, &CentralWidget::slotCarReverseCmd); return true; case Qt::Key_Right: joystick->setRightButtonPressed(true); keyPress(key, &CentralWidget::slotCarRightCmd); return true; case Qt::Key_Left: joystick->setLeftButtonPressed(true); keyPress(key, &CentralWidget::slotCarLeftCmd); return true; case Qt::Key_Space: hornSignalButton->setDown(true); keyPress(key, &CentralWidget::slotHornSignalStart); return true; default: break; } } else if (event->type() == QEvent::KeyRelease) { int key = keyEvent->key(); switch (key) { case Qt::Key_Up: case Qt::Key_Down: case Qt::Key_Right: case Qt::Key_Left: case Qt::Key_Space: keyReleaseDelayed(key); return true; default: break; } } return false; }
HEIMY_API void say(char* &text, bool send){ for(int i = 0; i < (int) strlen(text); i++){ keyPress(toupper(text[i]), FALSE); Sleep(1); } if(send) { keyPress(0x0D, FALSE); } }
int main (int argc, char* argv[]) { pthread_create(&g_BrowserMain, NULL, BrowserMain, NULL); //pthread_join(g_BrowserMain, NULL); while(1) { sleep(2); keyPress("blue", 0); keyPress("blue", 1); } return 0; }
bool MapEditorToolBase::keyPressEvent(QKeyEvent* event) { active_modifiers = Qt::KeyboardModifiers(event->modifiers() | (key_button_bar ? key_button_bar->activeModifiers() : 0)); #if defined(Q_OS_MAC) // FIXME: On Mac, QKeyEvent::modifiers() seems to return the keyboard // modifier flags that existed immediately before the event occurred. // This is in contradiction to the documenation for QKeyEvent::modifiers(), // but the documented behaviour of (parent) QInputEvent::modifiers(). // Qt5 doc says QKeyEvent::modifiers() "cannot always be trusted." ... switch (event->key()) { case Qt::Key_Shift: active_modifiers |= Qt::ShiftModifier; break; case Qt::Key_Control: active_modifiers |= Qt::ControlModifier; break; case Qt::Key_Alt: active_modifiers |= Qt::AltModifier; break; case Qt::Key_Meta: active_modifiers |= Qt::MetaModifier; break; default: ; // nothing } #endif return keyPress(event); }
int main() { int mode, i; mode = welcomePage(); global.score = 0; global.life = 3; global.gameover = 0; global.dou = 308; gameInitial(); /* initialize ai */ if (mode == 0) { for (i = 0; i < 4; i++) foolConstruct(&ghost[i].ai, ghost[i].speed, pacman.speed, i); } else if (mode == 1) { for (i = 0; i < 4; i++) normalConstruct(&ghost[i].ai, ghost[i].speed, pacman.speed, i); } else if (mode == 2) { for (i = 0; i < 4; i++) normalConstruct(&ghost[i].ai, ghost[i].speed, pacman.speed, i); } while(1) { keyPress(); process(); if (global.gameover) { gameOverPage(global.score); break; } } text_mode(); }
void Game::ProcessKeyDownEvent(int keyDownEvent) { if (keyDownEvent == 123) { keyPress(KeyRightArrow); } else if (keyDownEvent == 124) { keyPress(KeyLeftArrow); } else if (keyDownEvent == 126) { keyPress(KeyUpArrow); } else if (keyDownEvent == 125) { keyPress(KeyDownArrow); } }
void Navigator::doKeyPress (QKeyEvent *key) { switch (key->key()) { case Qt::Key_Delete: key->accept(); emit keyPress(key->state(), key->key()); break; case Qt::Key_Left: // segfaults if we dont trap this case Qt::Key_Right: // segfaults if we dont trap this key->accept(); break; case Qt::Key_Enter: case Qt::Key_Return: key->accept(); checkDirectory(item(currentItem())); break; case Qt::Key_Home: key->accept(); setHome(); Q3ListBox::keyPressEvent(key); break; default: key->accept(); Q3ListBox::keyPressEvent(key); break; } }
bool ShortcutCaptureDialog::eventFilter(QObject* /*o*/, QEvent* e) { if (e->type() == QEvent::KeyPress) { keyPress(static_cast<QKeyEvent*>(e)); return true; } return false; }
void GTKeyboardDriver::keyClick(GUITestOpStatus &os, char key, int modifiers) { GT_CHECK(key != 0, "key = 0"); if (modifiers==GTKeyboardDriver::key["ctrl"]) modifiers=GTKeyboardDriver::key["cmd"]; keyPress(os, key, modifiers); keyRelease(os, key, modifiers); }
void GTKeyboardDriver::keyClick(GUITestOpStatus &os, char key, int modifiers) { GT_CHECK(key != 0, "key = 0"); keyPress(os, key, modifiers); keyRelease(os, key, modifiers); GTGlobals::sleep(10); }
void keyboardCallback(unsigned char key, int x, int y) { if(key==27) exit(0); if(!sCamera->handleKey(key, x, y)) keyPress(key); }
void ParupaintChatInput::keyPressEvent(QKeyEvent * event) { if(event->key() == Qt::Key_Return){ emit returnPressed(); event->accept(); return; } emit keyPress(event); QLineEdit::keyPressEvent(event); }
void MSWidget::keyTranslateNotify(MSWidget *pWidget_,const XEvent *pEvent_, KeySym keysym_,unsigned int state_,const char *pString_) { MSKeyPress keyPress(keysym_,state_); if (pWidget_!=0) { if ( pWidget_->keyTranslate(keyPress) == MSTrue); else keyPressNotify(pWidget_,pEvent_,keysym_,state_,pString_); } }
void X11Device::eventLoop(size_t passes) { std::cerr << "Starting event loop..." << std::endl; while (passes--) { int redraw = 0; XEvent event; int width, height; reshape_func reshape = 0; key_func keyPress = 0; // draw_func draw = 0; XNextEvent(_display, &event); switch (event.type) { case Expose: redraw = 1; break; case ConfigureNotify: if (reshape) { width = event.xconfigure.width; height = event.xconfigure.height; reshape(event.xconfigure.width, event.xconfigure.height); } break; case KeyPress: { char buffer[10]; int r, code; code = XLookupKeysym(&event.xkey, 0); if (!keyPress || !keyPress(code)) { r = XLookupString(&event.xkey, buffer, sizeof(buffer), NULL, NULL); if (buffer[0] == 27) { // escape return; } else { std::cerr << buffer; } } } redraw = 1; break; default: ; // no-op } if (redraw) { // draw(); // eglSwapBuffers(egl_dpy, egl_surf); } } // end of while passes }
int inputManager::update(void) { SDL_Event currentEvent; while ( !messageP.empty() ) { AssetManager::lockMutex( inputManager::mutex_event ); currentEvent = messageP.receiveMessage(); AssetManager::unlockMutex( inputManager::mutex_event ); if (currentEvent.type == SDL_ACTIVEEVENT) { if ( currentEvent.active.state & SDL_APPINPUTFOCUS ) { if (currentEvent.active.gain==0) { active = false; SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_ShowCursor(SDL_ENABLE); } else { active = true; SDL_ShowCursor(SDL_DISABLE); SDL_WM_GrabInput(SDL_GRAB_ON); } } } if (active) { switch (currentEvent.type) { case SDL_KEYDOWN: case SDL_KEYUP: keyPress(currentEvent); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: mousePress(currentEvent); break; case SDL_MOUSEMOTION: mouseMotion(currentEvent); break; default: break; } } } return 0; }
static void key_callback(GLFWwindow *w, int key, int scancode, int action, int mods) { int i; if ((key == GLFW_KEY_ESCAPE || key == GLFW_KEY_Q) && action == GLFW_PRESS) { glfwSetWindowShouldClose(w, GL_TRUE); } for (i = 0; i < BARS; i++) { // look for the right key if (key == keys[i]) { keyPress(i, key); break; } } }
void MSWidget::keyPressEvent(const XEvent *pEvent_) { char buf[16]; KeySym keysym; int len=XLookupString((XKeyEvent *)pEvent_,buf,8,&keysym,NULL); buf[len]='\0'; #ifdef MS_KEYPAD_BUG server()->correctKeypadKeys(pEvent_,keysym,pEvent_->xkey.state,buf); #endif keyPress(pEvent_,keysym,pEvent_->xkey.state,buf); }
void gameController::handleEvents() { static SDL_Event event; while(SDL_PollEvent(&event)) { fsPoint2f p = m_oMouseLocWorld.loc; switch(event.type) { case SDL_MOUSEMOTION: mouseMove(event.button.x,event.button.y, 0); break; case SDL_MOUSEBUTTONDOWN: mouseDown(p.x,p.y ,0); break; case SDL_MOUSEBUTTONUP: mouseUp(p.x,p.y ,0); break; /* //case SDL_ACTIVEEVENT: //Something's happend with our focus //If we lost focus or we are iconified, we //shouldn't draw the screen if (event.active.gain == 0) isActive = false; else isActive = true; */ break; case SDL_VIDEORESIZE: resizeWindow(event.resize.w, event.resize.h); break; case SDL_KEYDOWN: // handle key presses keyPress(&event.key.keysym); break; case SDL_QUIT: // handle quit requests done = true; break; default: break; } } }
bool ApplicationSettingsFile::Load(File file) { if (!file.exists()) return false; configFile = file.getFullPathName(); String jsonString = file.loadFileAsString(); var json; Result result = JSON::parse(jsonString, json); if (result.ok()) { DynamicObject* obj = json.getDynamicObject(); if (obj == nullptr) return false; if(obj->hasProperty("PlayType")) setPlayType((SoundPlayType)(int)obj->getProperty("PlayType")); if (obj->hasProperty("UseGlobalHooks")) setUseGlobalHooks((bool)obj->getProperty("UseGlobalHooks")); if (obj->hasProperty("StopAllSoundKeyPresses")) { var keyPresses = obj->getProperty("StopAllSoundKeyPresses"); if (keyPresses.isArray()) { for (int i = 0; i < keyPresses.size(); ++i) { var jsonKeyPress(keyPresses[i]); if (jsonKeyPress.isVoid()) continue; DynamicObject* jsonKeyPressObj = jsonKeyPress.getDynamicObject(); if (jsonKeyPressObj == nullptr) continue; int keyCode = (int)jsonKeyPressObj->getProperty("KeyCode"); int modifierFlags = (int)jsonKeyPressObj->getProperty("ModifierFlags"); juce::juce_wchar textCharacter = (juce_wchar)((int)jsonKeyPressObj->getProperty("TextCharacter")); ModifierKeys modifierKeys; modifierKeys = modifierKeys.withFlags(modifierFlags); KeyPress keyPress(keyCode, modifierKeys, textCharacter); stopAllSoundsKeys.add(keyPress); } } } } return true; }
void MyInputPanelContext::sendString(int keyCode) { // qDebug()<<"sendString"; // QPointer<QWidget> w = focusWidget(); QPointer<QWidget> w = inputPanel->getFocusedWidget(); if (!w) return; QKeyEvent keyPress(QEvent::KeyPress, keyCode, Qt::NoModifier, QChar(keyCode)); QApplication::sendEvent(w, &keyPress); // if (!w) // return; // QKeyEvent keyRelease(QEvent::KeyPress, QChar('o').unicode(), Qt::NoModifier, text); // QApplication::sendEvent(w, &keyRelease); }
void MyInputPanelContext::sendCharacter(QChar character) { QPointer<QWidget> w = focusWidget(); if (!w) return; QKeyEvent keyPress(QEvent::KeyPress, character.unicode(), Qt::NoModifier, QString(character)); QApplication::sendEvent(w, &keyPress); if (!w) return; QKeyEvent keyRelease(QEvent::KeyPress, character.unicode(), Qt::NoModifier, QString()); QApplication::sendEvent(w, &keyRelease); }
void GTKeyboardDriver::keyPress(GUITestOpStatus &os, char key, int modifiers) { GT_CHECK(key != 0, "key = 0"); const bool isChanged = extractShiftModifier(key); if (isChanged) { CGEventRef event = CGEventCreateKeyboardEvent(NULL, GTKeyboardDriver::key["shift"], true); GT_CHECK(event != NULL, "Can't create event"); CGEventPost(kCGSessionEventTap, event); CFRelease(event); } else { key = asciiToVirtual(key); } GTGlobals::sleep(1); keyPress(os, (int)key, modifiers); }
void GTKeyboardDriver::keyClick(GUITestOpStatus &os, char key, QList<int> modifiers){ switch (modifiers.size()) { case 0: keyClick(os, key); break; case 1: keyClick(os, key, modifiers.first()); break; default: int modifier = modifiers.takeLast(); foreach (int mod, modifiers) { keyPress(os, mod); } keyClick(os, key, modifier); foreach (int mod, modifiers) { keyRelease(os, mod); }
bool EHLevel::handleEvent(Event * event) { bool ret = false; switch(event->type()) { case EVENT_MOUSE_CLICK: { EMouse * mouseEvent = static_cast<EMouse *>(event); //Logger::write(Logger::ss << "Mouse Click " << mouseEvent->position().toString()); if(mouseEvent->button() == MOUSE_BUTTON_LEFT) { mouseLeftClick(mouseEvent->position()); } else if(mouseEvent->button() == MOUSE_BUTTON_RIGHT) { mouseRightClick(mouseEvent->position()); } ret = true; break; } case EVENT_MOUSE_MOTION: { EMouse * mouseEvent = static_cast<EMouse *>(event); mouseMotion(mouseEvent->position()); ret = true; break; } case EVENT_GAME_QUIT: { Game::instance()->setQuit(true); ret = true; break; } case EVENT_KEY_PRESS: { EKeyPress * keyEvent = static_cast<EKeyPress *>(event); keyPress(keyEvent->keyType()); ret = true; break; } } return ret; }
int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QMainWindow::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: keyPress((*reinterpret_cast< int(*)>(_a[1]))); break; case 1: doMouseLeftClick1(); break; case 2: doMouseLeftClick2(); break; case 3: mouseClick((*reinterpret_cast< int(*)>(_a[1]))); break; default: ; } _id -= 4; } return _id; }
void MSOptionMenu::keyPress(const XEvent *pEvent_,KeySym keysym_,unsigned int state_,const char *) { MSKeyPress keyPress(keysym_, state_); if (isProtected()==MSFalse&&optionMenu()!=0&& keyTranslate(keyPress)==MSFalse) { switch (keysym_) { case XK_Return: case XK_Up: case XK_Down: showMenu(pEvent_->xkey.time); break; default: break; } } }
Boolean MRJFrame::handleEvent(const EventRecord* event) { Boolean eventHandled = true; switch (event->what) { case nsPluginEventType_AdjustCursorEvent: idle(event->modifiers); break; case ::mouseDown: click(event); break; case keyDown: case autoKey: keyPress(event->message, event->modifiers); break; case keyUp: keyRelease(event->message, event->modifiers); break; case updateEvt: update(); break; case activateEvt: activate((event->modifiers & activeFlag) != 0); break; #if 0 case osEvt: resume((event->message & resumeFlag) != 0); eventHandled = false; break; #endif default: eventHandled = false; break; } return eventHandled; }
// watch for ctrl key; emit the key event to pass it on void ColorSelector::keyPressEvent ( QKeyEvent * e ) { bool closing = e->key() == Qt::Key_Escape; #ifdef Q_OS_MACX if (!closing) closing = e->key() == Qt::Key_W && (e->modifiers() ==Qt::ControlModifier); #endif if (closing) { emit done(); } else { if (mHotFlag != NO_HOT_SLIDER && e->key() == mHotKey) { mCtrlPressed = true; grabKeyboard(); } emit (keyPress(e)); } }
int mainForm::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QWidget::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: keyPress((*reinterpret_cast< uint(*)>(_a[1]))); break; case 1: changeFont(); break; case 2: changeLanguage((*reinterpret_cast< int(*)>(_a[1]))); break; case 3: about(); break; case 4: readSettings(); break; case 5: writeSettings(); break; case 6: setButtonText((*reinterpret_cast< QString(*)>(_a[1]))); break; default: ; } _id -= 7; } return _id; }
void TextBox::mousePress(int x, int y, int button) { if (hasMouse() && button == MouseInput::LEFT) { mCaretRow = y / getFont()->getHeight(); if (mCaretRow >= (int)mTextRows.size()) { mCaretRow = mTextRows.size() - 1; } mCaretColumn = getFont()->getStringIndexAt(mTextRows[mCaretRow], x); } else if (hasMouse() && button == MouseInput::MIDDLE) { std::string str; if (GetClipboard(str) >= 0) { for (size_t i = 0; i < str.size(); ++i) { keyPress(Key(str[i])); } } } }