// The GTK keypress callback bool EventManager::onDialogKeyPress(GdkEventKey* ev, Gtk::Window* window) { // Pass the key event to the connected dialog window and see if it can process it (returns TRUE) // greebo: gtkmm is not exposing this function?? bool keyProcessed = gtk_window_propagate_key_event(window->gobj(), ev); // Get the focus widget, is it an editable widget? Gtk::Widget* focus = window->get_focus(); bool isEditableWidget = dynamic_cast<Gtk::Editable*>(focus) != NULL || dynamic_cast<Gtk::TextView*>(focus) != NULL; // never pass onKeyPress event to the accelerator manager if an editable widget is focused // the only exception is the ESC key if (isEditableWidget && ev->keyval != GDK_Escape) { return keyProcessed; } if (!keyProcessed) { // The dialog window returned FALSE, pass the key on to the default onKeyPress handler onKeyPress(ev, window); } // If we return true here, the dialog window could process the key, and the GTK callback chain is stopped return keyProcessed; }
//-------------------------------------------------------------- void ofxMSAInteractiveObject::_keyPressed(ofKeyEventArgs &e) { int key = e.key; if(verbose) printf("ofxMSAInteractiveObject::_keyPressed(key: %i)\n", key); if(!enabled) return; if(isMouseOver()) onKeyPress(key); keyPressed(key); }
bool ControllerKeyboardCallback::processKeyPress(QKeyEvent* event) { if (onKeyPress) return onKeyPress(event); return false; }
void updateGL() { updateMouse(); int key = getKey(); if ( key != -1 && key != keyPressed ){ keyPressed = key; onKeyPress(key); } }
void Keyboard::keyPressed( const KeyEvent& keyEvent ) { // Ignore automatic key repeat. if( keyState[(int)keyEvent.keyCode] ) return; keyState[(int)keyEvent.keyCode] = true; lastKey = keyEvent.keyCode; onKeyPress(keyEvent); }
bool DesignerEventHandler::eventFilter(QObject* o, QEvent* e) { switch (e->type()){ // case QEvent::ContextMenu: // qDebug () << "context menu event !!!"; // break; case QEvent::MouseButtonPress: //context_widget = dynamic_cast<VtlWidget*>(o); onMousePress((QMouseEvent*)e); break; case QEvent::MouseMove: onMouseMove((QMouseEvent*)e); break; case QEvent::MouseButtonRelease: onMouseRelease((QMouseEvent*)e); //context_widget = 0; break; case QEvent::MouseButtonDblClick: showWidgetProperties(); break; case QEvent::ContextMenu: //qDebug () << o->className(); qDebug () << "context menu event !!!"; onContextMenu((QContextMenuEvent*)e); break; case QEvent::KeyPress: onKeyPress((QKeyEvent*)e); break; // case QEvent::Paint: // onPaintEvent ( static_cast<QPaintEvent*>(e) ); // break; case OutsideEvent::Outside:{ VtlWidget * w = ((OutsideEvent *)e)->widget(); if (selections[w]){ selections[w]->updateSelectionPos(); } } return true; case AddToSelEvent::AddToSel: if (static_cast<AddToSelEvent*>(e)->clearSel()) clearSelection( ); addWidgetToSelection(static_cast<AddToSelEvent*>(e)->widget()); return true; default: break; } return QObject::eventFilter(o, e); }
NewPassCodePage::NewPassCodePage(QWidget *parent) : Dialog(parent), _passcode(Tr("New PassCode")), _confirm(Tr("Confirm PassCode")), _save(Tr("Save")), _cancel(Tr("Cancel")) { _main.setContentsMargins(24, 24, 24, 8); _main.addLayout(&_active); _main.addLayout(&_pass); _main.addLayout(&_actions); setLayout(&_main); init(); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); QObject::connect(&_cancel, SIGNAL(clicked()), this, SLOT(onCancel())); QObject::connect(&_save, SIGNAL(clicked()), this, SLOT(onSave())); QObject::connect(this, SIGNAL(keyPressd(Qt::Key)), this, SLOT(onKeyPress(Qt::Key))); }
LanguagePage::LanguagePage(QWidget *parent) : Dialog(parent), _fa(Tr("Persian")), _en(Tr("English")), _restart(Tr("Ok")), _langChenged(false) { _main.setContentsMargins(24, 24, 24, 8); setLayout(&_main); _main.addWidget(&_fa); _main.addWidget(&_en); _main.addWidget(&_restart); _group.addButton(&_fa, 0); _group.addButton(&_en, 1); checkLanguage(); QObject::connect(&_group, SIGNAL(buttonClicked(int)), this, SLOT(onLangchange(int))); QObject::connect(&_restart, SIGNAL(clicked()), this, SLOT(onRestart())); QObject::connect(this, SIGNAL(keyPressd(Qt::Key)), this, SLOT(onKeyPress(Qt::Key))); }
bool UIWidget::propagateOnKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter) { // do a backup of children list, because it may change while looping it UIWidgetList children; for(const UIWidgetPtr& child : m_children) { // events on hidden or disabled widgets are discarded if(!child->isExplicitlyEnabled() || !child->isExplicitlyVisible()) continue; // key events go only to containers or focused child if(child->isFocused()) children.push_back(child); } for(const UIWidgetPtr& child : children) { if(child->propagateOnKeyPress(keyCode, keyboardModifiers, wouldFilter)) return true; } return onKeyPress(keyCode, keyboardModifiers, wouldFilter); }
void DisplayWindow::operator ()() { while (true) { if (!dispImg.empty()){ Mat endImage; imLock.lock(); process(dispImg, endImage, mode); imLock.unlock(); if (dragging && mode==0){ rectangle(endImage, dragStartL, currentPos, Scalar(0,0,255)); } imshow(windowName,endImage); } else { imshow(windowName,Mat::zeros(Size(100,100), CV_8UC3)); } int c = waitKey(10); onKeyPress(c); if((char)c == 27) {break;} } running = false; }
void Platform::loop() { SDL_Event event; while(!m_done) { Scheduler::Poll(); while(!m_done && SDL_PollEvent(&event)) { switch(event.type) { #if defined(WIN32) // mouse case SDL_MOUSEMOTION: onMouseMove(1, {event.motion.x * g_graphic->getDrawDimension().w / g_graphic->getWindowWidth(), event.motion.y * g_graphic->getDrawDimension().h / g_graphic->getWindowHeight() }); break; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: { Point point; point.x = event.motion.x * g_graphic->getDrawDimension().w / g_graphic->getWindowWidth(); point.y = event.motion.y * g_graphic->getDrawDimension().h / g_graphic->getWindowHeight(); onMousePress(event.button.button, point, event.button.state); break; } // finger #elif defined(ANDROID) case SDL_FINGERMOTION: { Point pos = {(int32_t)(event.tfinger.x * g_graphic->getDrawDimension().w), (int32_t)(event.tfinger.y * g_graphic->getDrawDimension().h)}; onMouseMove(1 + event.tfinger.fingerId, pos); break; } case SDL_FINGERDOWN: case SDL_FINGERUP: { Point pos = {(int32_t)(event.tfinger.x * g_graphic->getDrawDimension().w), (int32_t)(event.tfinger.y * g_graphic->getDrawDimension().h)}; onMousePress(1 + event.tfinger.fingerId, pos, event.type == SDL_FINGERDOWN); break; } #endif case SDL_KEYDOWN: onKeyPress((uint16_t)event.key.keysym.sym, true); break; case SDL_KEYUP: onKeyPress((uint16_t)event.key.keysym.sym, false); break; case SDL_DROPFILE: { std::string path = g_fileManager.resolvePath(event.drop.file); onDragFile(path); SDL_free(event.drop.file); break; } case SDL_WINDOWEVENT: { switch(event.window.event) { case SDL_WINDOWEVENT_FOCUS_GAINED: m_hasWindowFocus = true; break; case SDL_WINDOWEVENT_FOCUS_LOST: m_hasWindowFocus = false; break; case SDL_WINDOWEVENT_RESIZED: case SDL_WINDOWEVENT_SIZE_CHANGED: { g_graphic->init(event.window.data1, event.window.data2); g_painter.resetDrawArea(); g_graphic->render(); g_lua["onWindowResize"].call(event.window.data1, event.window.data2); break; } } break; } case SDL_APP_LOWMEMORY: LOGI("Low Memory"); case SDL_APP_TERMINATING: LOGI("Terminating"); case SDL_QUIT: LOGI("Quit"); m_done = true; break; } } if(!m_done) g_graphic->render(); } }
int main (int argc, char **argv) { /* generic purpose counter */ int i, j, count; signed char ch; unsigned short cmd_opts = 0; char *devnode = NULL; active = 1; /* must be set to true to run binds */ /* default conf_file */ /* fixme: what if there's no HOME environ var? */ conf_file = calloc(strlen(getenv("HOME")) + strlen("/.ebindkeysrc"), sizeof(char)); sprintf(conf_file, "%s/.ebindkeysrc", getenv("HOME")); /* work through command line options */ while( (ch = getopt(argc, argv, "f:dslrhne:")) != -1) { switch (ch) { case 'f': /* override default conf file */ free(conf_file); conf_file = strdup(optarg); break; case 'd': /* don't fork at startup */ cmd_opts |= EBK_NODAEMON; break; case 's': /* don't fork when executing actions. */ cmd_opts |= EBK_NOFORK; break; case 'l': /* list the names of keys */ break; case 'r': /* report key presses / releases */ cmd_opts |= EBK_SHOWKEYS; break; case 'n': devnode = strdup(optarg); break; case ':': exit(1); break; case 'h': break; case 'e': cmd_opts |= EBK_EXPERIMENTAL; break; /*default: printf("Usage: %s [options]\n", argv[0]); exit(1); break; */ } } /* check if a conf file exists, if not, bitch at user */ FILE *conf_check; if (! (conf_check = fopen(conf_file, "r")) ) // check home or command line dir first { fprintf(stderr, "%s: could not open config file %s\n", argv[0], conf_file); free(conf_file); conf_file = "/etc/ebindkeysrc"; if (! (conf_check = fopen(conf_file, "r")) ) // check etc { fprintf(stderr, "%s: could not open config file %s\n", argv[0], conf_file); exit(2); } else fclose(conf_check); } else fclose(conf_check); printf("%s: Loaded config file %s\n", argv[0], conf_file); settings *conf = load_settings(conf_file); /* combine command line options with setting file options. * command line options override conf file */ conf->opts |= cmd_opts; if (devnode != NULL) conf->dev = devnode; event *event_first = conf->event_first; event_list_global = &event_first; /* initialize key_press list */ key_press *list_start = calloc(1,sizeof(key_press)); list_start->next = NULL; /* points to the last struct in the linked list */ key_press *list_end = list_start; key_press *list_cur, *list_prev; struct input_event ievent; /* No buffering, for now. */ int eventfh; int ufile; int ufile_mouse; /* open uinput for exclusive access to the input device */ if(!openUInput(&ufile, &ufile_mouse, &eventfh, conf->dev)) exit(3); /* How does a good parent prevent his children from becoming * part of the zombie hoard? He ignores them! */ signal(SIGCHLD, SIG_IGN); signal(SIGUSR1, reload_settings); if ( ! ( ISSET(conf->opts, EBK_NODAEMON) ) ) if (fork()) exit(0); for(;;) { if ( read(eventfh, &ievent, sizeof(struct input_event)) == -1 ) { /* read() will always get sizeof(struct input_event) number * of bytes, the kernel gurantees this, so we only worry * about reads error. */ perror("Error reading device"); exit(3); } /* Do nothing if lid is closed */ if ( lidstate() != LID_CLOSED ) { int bFiltered = 0; if(bProcessMouse || bTempProcessMouse){ bFiltered = process_mouse_event(ufile_mouse, &ievent); if(bFiltered) continue; } /* Key has been pressed */ if ( ievent.type == EV_KEY && ievent.value == EBK_KEY_DOWN ) { if ( ISSET(conf->opts, EBK_SHOWKEYS) ) { printf(">%X<\n", ievent.code); fflush(stdout); } /*reset the keyboard timer and turn on the lights */ onKeyPress(); /* if no other keys are pressed, filter the keystroke */ if(list_start->next == NULL) bFiltered = filterKeyStroke(ufile, ufile_mouse, &ievent, ISSET(conf->opts, EBK_EXPERIMENTAL)); // if(bFiltered) continue; /* add to depressed struct */ list_end->code = ievent.code; list_end->next = calloc(1,sizeof(key_press)); list_end = list_end->next; list_end->next = NULL; Match_keysToEvent(list_start, event_first, (ISSET(conf->opts, EBK_NOFORK)), cfg_false); } /* Key has been released */ if ( ievent.type == EV_KEY && ievent.value == EBK_KEY_UP ) { if ( ISSET(conf->opts,EBK_SHOWKEYS) ) { printf("<%X>\n", ievent.code); fflush(stdout); } Match_keysToEvent(list_start, event_first, (ISSET(conf->opts, EBK_NOFORK)), cfg_true); /* remove from depressed struct */ list_cur = list_start; list_prev = NULL; while (list_cur->code != ievent.code && list_cur->next != NULL) { list_prev = list_cur; list_cur = list_cur->next; } /* if the bellow is true, most likely, a key was released * but ebindkeys didn't detect the press */ if (list_cur->next == NULL) continue; if (list_prev == NULL) { /* no previous? we're at start! */ list_start = list_cur->next; } else { list_prev->next = list_cur->next; } free(list_cur); if(ievent.code == KEY_LEFTCTRL) bTempProcessMouse=0; } if(!bFiltered) write(ufile, &ievent, sizeof(struct input_event)); } } if(ioctl(ufile, UI_DEV_DESTROY) < 0) fprintf(stderr, "Error destroying uinput device!"); if(ioctl(ufile_mouse, UI_DEV_DESTROY) < 0) fprintf(stderr, "Error destroying uinput device!"); close(eventfh); close(ufile); close(ufile_mouse); return 0; }
bool PaintBox::Key( dword key, int count ) { onKeyPress(key); return false; }
LRESULT CALLBACK WindowsWindow::dispatch( const HWND hWnd , const UINT message , const WPARAM wParam , const LPARAM lParam) { assert(!m_hWnd || hWnd == m_hWnd); if (!m_hWnd) return DefWindowProc(hWnd, message, wParam, lParam); // Windows Messages: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644927(v=vs.85).aspx#windows_messages switch (message) { case WM_QUIT: case WM_CLOSE: onClose(); break; case WM_DESTROY: onDestroy(); break; case WM_SIZE: onResize(LOWORD(lParam), HIWORD(lParam)); break; case WM_PAINT: onRepaint(); break; case WM_USER_IDLE: onIdle(); break; case WM_KEYDOWN: case WM_SYSKEYDOWN: if(!onKeyPress(LOWORD(wParam))) DefWindowProc(hWnd, message, wParam, lParam); break; case WM_KEYUP: case WM_SYSKEYUP: if(!onKeyRelease(LOWORD(wParam))) DefWindowProc(hWnd, message, wParam, lParam); break; //case WM_ACTIVATE: // // Check for minimization. // if (!HIWORD(wParam)) // m_eventHandler->activateEvent(); // else // m_eventHandler->minimizeEvent(); // break; case WM_SYSCOMMAND: // Absorb some system commands. switch (wParam) { case SC_SCREENSAVE: case SC_MONITORPOWER: return 0; } default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
//============================================================================== void CEvent::onEvent(SDL_Event *anEvent) { switch(anEvent->type) { case SDL_WINDOWEVENT: { switch(anEvent->window.event) { case SDL_WINDOWEVENT_ENTER:{ onMouseFocus(); break; } case SDL_WINDOWEVENT_LEAVE:{ onMouseBlur(); break; } case SDL_WINDOWEVENT_FOCUS_GAINED: { onInputFocus(); break; } case SDL_WINDOWEVENT_FOCUS_LOST: { onInputBlur(); break; } case SDL_WINDOWEVENT_RESTORED: { onRestore(); break; } case SDL_WINDOWEVENT_MINIMIZED: { onMinimize(); break; } } break; } case SDL_KEYDOWN: { onKeyPress(anEvent->key.keysym.sym, anEvent->key.keysym.mod); break; } case SDL_KEYUP: { onKeyRelease(anEvent->key.keysym.sym,anEvent->key.keysym.mod); break; } case SDL_MOUSEMOTION: { onMouseMove(anEvent->motion.x, anEvent->motion.y, anEvent->motion.xrel, anEvent->motion.yrel,(anEvent->motion.state&SDL_BUTTON(SDL_BUTTON_LEFT))!=0,(anEvent->motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT))!=0,(anEvent->motion.state&SDL_BUTTON(SDL_BUTTON_MIDDLE))!=0); break; } case SDL_MOUSEBUTTONDOWN: { switch(anEvent->button.button) { case SDL_BUTTON_LEFT: { onLButtonDown(anEvent->button.x,anEvent->button.y); break; } case SDL_BUTTON_RIGHT: { onRButtonDown(anEvent->button.x,anEvent->button.y); break; } case SDL_BUTTON_MIDDLE: { onMButtonDown(anEvent->button.x,anEvent->button.y); break; } } break; } case SDL_MOUSEBUTTONUP: { switch(anEvent->button.button) { case SDL_BUTTON_LEFT: { onLButtonUp(anEvent->button.x,anEvent->button.y); break; } case SDL_BUTTON_RIGHT: { onRButtonUp(anEvent->button.x,anEvent->button.y); break; } case SDL_BUTTON_MIDDLE: { onMButtonUp(anEvent->button.x,anEvent->button.y); break; } } break; } case SDL_QUIT: { onExit(); break; } case SDL_SYSWMEVENT: { //Ignore break; } case SDL_WINDOWEVENT_RESIZED: { onResize(anEvent->window.data1,anEvent->window.data2); break; } case SDL_WINDOWEVENT_EXPOSED: { onExpose(); break; } default: { onUser(anEvent->user.type,anEvent->user.code,anEvent->user.data1,anEvent->user.data2); break; } } }
void renderThread(int argc, char **argv) { // Prepare viewport glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); // Setup setup(); // Turn on Alpha blending glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // Clear the background glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); int textureCounter = 0; //Load the the resources (textures) for (uint i = 1; i < argc ; i++){ std::string argument = std::string(argv[i]); if (argument == "-x" || argument == "-y" || argument == "-w" || argument == "--width" || argument == "-h" || argument == "--height" ) { i++; } else if ( argument == "--square" || argument == "-l" || argument == "--life-coding" ) { } else if ( argument == "-m" ) { bCursor = true; cursor.init(); } else if ( argument == "-s" || argument == "--sec") { i++; argument = std::string(argv[i]); timeLimit = getFloat(argument); std::cout << "Will exit in " << timeLimit << " seconds." << std::endl; } else if ( argument == "-o" ){ i++; argument = std::string(argv[i]); if( haveExt(argument,"png") ){ outputFile = argument; std::cout << "Will save screenshot to " << outputFile << " on exit." << std::endl; } else { std::cout << "At the moment screenshots only support PNG formats" << std::endl; } } else if (argument.find("-") == 0) { std::string parameterPair = argument.substr(argument.find_last_of('-')+1); i++; argument = std::string(argv[i]); Texture* tex = new Texture(); if( tex->load(argument) ){ textures[parameterPair] = tex; std::cout << "Loading " << argument << " as the following uniform: " << std::endl; std::cout << " uniform sampler2D " << parameterPair << "; // loaded"<< std::endl; std::cout << " uniform vec2 " << parameterPair << "Resolution;"<< std::endl; } } else if ( haveExt(argument,"png") || haveExt(argument,"PNG") || haveExt(argument,"jpg") || haveExt(argument,"JPG") || haveExt(argument,"jpeg") || haveExt(argument,"JPEG") ) { Texture* tex = new Texture(); if( tex->load(argument) ){ std::string name = "u_tex"+getString(textureCounter); textures[name] = tex; std::cout << "Loading " << argument << " as the following uniform: " << std::endl; std::cout << " uniform sampler2D " << name << "; // loaded"<< std::endl; std::cout << " uniform vec2 " << name << "Resolution;"<< std::endl; textureCounter++; } } } // Render Loop while (isGL() && bPlay) { // Update updateGL(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw draw(); // Swap the buffers renderGL(); if ( timeLimit > 0.0 && getTime() > timeLimit ) { onKeyPress('s'); bPlay = false; } } }
void Sprite::keyPressEvent(QKeyEvent *event) { emit onKeyPress(event->key()); }