static void onMouseWheel( HWND hwnd, UINT fwKeys, int zDelta, int x, int y ) { if ( 0 != fwKeys ) { ; } else { UINT lines_to_scroll = 0; SystemParametersInfo( SPI_GETWHEELSCROLLLINES, 0, &lines_to_scroll, 0 ); if ( WHEEL_PAGESCROLL == lines_to_scroll ) { if ( zDelta < 0 ) { scroll( hwnd, 1, 0 ); } else if ( 0 < zDelta ) { scroll( hwnd, -1, 0 ); } } else if ( 0 < lines_to_scroll ) { // TODO -- adjust for page size/granularity if ( zDelta < 0 ) { const UINT right_key = isVertical( hwnd ) ? VK_DOWN : VK_RIGHT; for ( UINT line = 0; line < lines_to_scroll; ++line ) { onKey( hwnd, right_key, true, 1, 0 ); } } else if ( 0 < zDelta ) { const UINT left_key = isVertical( hwnd ) ? VK_UP : VK_LEFT; for ( UINT line = 0; line < lines_to_scroll; ++line ) { onKey( hwnd, left_key, true, 1, 0 ); } } } } }
void WinapiKeyboardContext::keyEvent(WinapiWindowContext* wc, unsigned int vkcode, unsigned int lparam) { auto scancode = HIWORD(lparam); auto keycode = winapiToKeycode(vkcode); unsigned char state[256] {}; ::GetKeyboardState(state); std::string utf8; wchar_t utf16[64]; auto bytes = ::ToUnicode(vkcode, scancode, state, utf16, 64, 0); if(bytes > 0) { utf16[bytes] = L'\0'; auto utf16string = reinterpret_cast<char16_t*>(utf16); utf8 = nytl::toUtf8(utf16string); } bool pressed = !(scancode & (1 << 15)); onKey(*this, keycode, utf8, pressed); if(wc != focus_) warning("ny::WinapiKC::keyEvent: event handler <-> focus inconsistency"); if(wc && wc->eventHandler()) { KeyEvent keyEvent(wc->eventHandler()); keyEvent.pressed = pressed; keyEvent.keycode = keycode; keyEvent.unicode = std::move(utf8); wc->eventHandler()->handleEvent(keyEvent); } }
void OSXKeyState::handleModifierKey(void* target, UInt32 virtualKey, KeyID id, bool down, KeyModifierMask newMask) { KeyButton button = mapVirtualKeyToKeyButton(virtualKey); onKey(button, down, newMask); sendKeyEvent(target, down, false, id, newMask, 0, button); }
void processEvents() { while (XPending(x_dpy)) { XEvent ev; XNextEvent(x_dpy, &ev); switch (ev.type) { case KeyPress: case KeyRelease: onKey(ev.xkey.window, ev.xkey.state, ev.xkey.keycode, ev.type == KeyPress ? 1 : 2); break; case ButtonPress: case ButtonRelease: onMouse(ev.xbutton.window, ev.xbutton.x, ev.xbutton.y, ev.xbutton.state, ev.xbutton.button, ev.type == ButtonPress ? 1 : 2); break; case MotionNotify: onMouse(ev.xmotion.window, ev.xmotion.x, ev.xmotion.y, ev.xmotion.state, 0, 0); break; case FocusIn: case FocusOut: onFocus(ev.xmotion.window, ev.type == FocusIn); break; case Expose: // A non-zero Count means that there are more expose events coming. For // example, a non-rectangular exposure (e.g. from a partially overlapped // window) will result in multiple expose events whose dirty rectangles // combine to define the dirty region. Go's paint events do not provide // dirty regions, so we only pass on the final X11 expose event. if (ev.xexpose.count == 0) { onExpose(ev.xexpose.window); } break; case ConfigureNotify: onConfigure(ev.xconfigure.window, ev.xconfigure.x, ev.xconfigure.y, ev.xconfigure.width, ev.xconfigure.height, DisplayWidth(x_dpy, DefaultScreen(x_dpy)), DisplayWidthMM(x_dpy, DefaultScreen(x_dpy))); break; case ClientMessage: if ((ev.xclient.message_type != wm_protocols) || (ev.xclient.format != 32)) { break; } Atom a = ev.xclient.data.l[0]; if (a == wm_delete_window) { onDeleteWindow(ev.xclient.window); } else if (a == wm_take_focus) { XSetInputFocus(x_dpy, ev.xclient.window, RevertToParent, ev.xclient.data.l[1]); } break; } } }
bool DesktopWindow::onMessage(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_HSCROLL: return onHScroll(wParam, lParam); case WM_VSCROLL: return onVScroll(wParam, lParam); case WM_ERASEBKGND: return onEraseBackground(reinterpret_cast<HDC>(wParam)); case WM_DEADCHAR: case WM_SYSDEADCHAR: return onDeadChar(wParam, lParam); case WM_DRAWCLIPBOARD: return onDrawClipboard(); case WM_CREATE: return onCreate(reinterpret_cast<LPCREATESTRUCT>(lParam)); case WM_SIZE: return onSize(wParam, lParam); case WM_DESTROY: return onDestroy(); case WM_CHAR: case WM_SYSCHAR: return onChar(wParam, lParam); case WM_KEYDOWN: case WM_KEYUP: case WM_SYSKEYDOWN: case WM_SYSKEYUP: return onKey(wParam, lParam); case WM_SETFOCUS: m_rfbKeySym->processFocusRestoration(); return true; case WM_KILLFOCUS: m_rfbKeySym->processFocusLoss(); return true; } return false; }
void WorldDrawer2d::keyboardCallbackFunction(unsigned char key, int posx, int posy){ if(key==KEY_ESC) glutExit(); //call client function onKey(key); }
void Events::onEventsKey(Uint8 a, SDLKey key) { bool b; if( a == SDL_KEYDOWN ) b=true; else b=false; switch (key) { case SDLK_RETURN: if(!altPressed) { onEnter(b); } onMyEnter(b); break; case SDLK_LEFT: onArrow(LEFT,b); break; case SDLK_RIGHT: onArrow(RIGHT,b); break; case SDLK_UP: onArrow(UP,b); break; case SDLK_DOWN: onArrow(DOWN,b); break; case SDLK_PLUS: onPlus(b); break; case SDLK_MINUS: onMinus(b); break; case SDLK_KP_PLUS: onPlus(b); break; case SDLK_KP_MINUS: onMinus(b); break; case SDLK_SPACE: onSpace(b); break; case SDLK_f: onF(b); onMyF(b); break; case SDLK_s: onS(b); onMyS(b); break; case SDLK_ESCAPE: onEsc(b); break; case SDLK_RCTRL: onCtrl(b); break; case SDLK_LCTRL: onCtrl(b); break; case SDLK_RALT: onAlt(b); onMyAlt(b); break; case SDLK_LALT: onAlt(b); onMyAlt(b); break; default: break; } onKey(b,key); char c=0; switch (key) { case SDLK_a: c='a'; break; case SDLK_b: c='b'; break; case SDLK_c: c='c'; break; case SDLK_d: c='d'; break; case SDLK_e: c='e'; break; case SDLK_f: c='f'; break; case SDLK_g: c='g'; break; case SDLK_h: c='h'; break; case SDLK_i: c='i'; break; case SDLK_j: c='j'; break; case SDLK_k: c='k'; break; case SDLK_l: c='l'; break; case SDLK_m: c='m'; break; case SDLK_n: c='n'; break; case SDLK_o: c='o'; break; case SDLK_p: c='p'; break; case SDLK_q: c='q'; break; case SDLK_r: c='r'; break; case SDLK_s: c='s'; break; case SDLK_t: c='t'; break; case SDLK_u: c='u'; break; case SDLK_w: c='w'; break; case SDLK_x: c='x'; break; case SDLK_y: c='y'; break; case SDLK_v: c='v'; break; case SDLK_z: c='z'; break; case SDLK_0: c='0'; break; case SDLK_1: c='1'; break; case SDLK_2: c='2'; break; case SDLK_3: c='3'; break; case SDLK_4: c='4'; break; case SDLK_5: c='5'; break; case SDLK_6: c='6'; break; case SDLK_7: c='7'; break; case SDLK_8: c='8'; break; case SDLK_9: c='9'; break; default: break; }; if(c) onNamedKey(b,c); }
void WorldDrawer2d::keyboardSpecialCallbackFunction(int key, int posx, int posy){ //call client function onKey(key); }
void DrawingWindow::specialFunction(int key, int x, int y) { onKey(key); }
void DrawingWindow::keyboardFunction(unsigned char key, int x, int y) { onKey(key); }
uint32 Editor::onMessage(uint32 message, uint32 wParam, uint32 lParam) { switch (message) { case WM_DESTROY: delete target; target = NULL; break; case WM_SETCURSOR: if (LOWORD(lParam) == HTCLIENT) { POINT pt; GetCursorPos(&pt); ScreenToClient(hWnd, &pt); if (pt.x < LeftMargin()) SetCursor(cursors[cArrow]); else if (selStart != caret) { pt.x = (pt.x - LeftMargin()) / chSize.cx + scrollPos.x; pt.y = pt.y / chSize.cy + scrollPos.y; if (pt.y < 0 || pt.y >= lines.length() || pt.x < 0 || pt.x >= lines[pt.y].text.length()) SetCursor(cursors[cBeam]); else { int offset = fromPoint(pt); int sela = (selStart < caret ? selStart : caret); int selb = (selStart < caret ? caret : selStart); if (offset >= sela && offset < selb) SetCursor(cursors[cArrow]); else SetCursor(cursors[cBeam]); } } else SetCursor(cursors[cBeam]); } else SetCursor(cursors[cArrow]); return TRUE; case WM_ERASEBKGND: return TRUE; case WM_PAINT: paint(); return 0; case WM_SIZE: if (hBitmap) { int wd = LOWORD(lParam); int ht = HIWORD(lParam); if (wd < 10) wd = 10; if (ht < 10) ht = 10; hBitmap = CreateCompatibleBitmap(hDC, wd, ht); SelectObject(hDC, hBitmap); } updateExtent(); return 0; case WM_SETFOCUS: placeCaret(); invalidate(); getParent()->notify(EN_FOCUSED, (uint32) this, 0); return 0; case WM_KILLFOCUS: DestroyCaret(); updateCaret(); invalidate(); return 0; case WM_LBUTTONDBLCLK: { POINT pt = paramToPoint(lParam); fixPoint(pt); int ptStart = wordEnd(lines[pt.y].text.c_str(), pt.x, -1); int ptEnd = wordEnd(lines[pt.y].text.c_str(), pt.x, 1); int offset = fromPoint(pt); selStart = offset - (pt.x - ptStart); caret = offset + (ptEnd - pt.x); updateCaret(); } return 0; case WM_LBUTTONDOWN: if (int(GET_X_LPARAM(lParam)) < int(settings->bpOffset - scrollPos.x * chSize.cx)) { POINT pt = paramToPoint(lParam); toggleBreakpoint(pt.y); } else { POINT pt = paramToPoint(lParam); int offset = fromPoint(pt); int sela = (selStart < caret ? selStart : caret); int selb = (selStart > caret ? selStart : caret); if (offset >= sela && offset < selb) { dragop = 1; uint32 fx = DoDragDropEx(CF_UNICODETEXT, CreateGlobalText(getSelection()), DROPEFFECT_MOVE | DROPEFFECT_COPY, hWnd); if (fx == DROPEFFECT_NONE) dragop = 0; //else if (fx != DROPEFFECT_COPY && dragop != 2) // replace(sela, selb, ""); } else SetCapture(hWnd); if (dragop == 0) { caret = offset; if (!(wParam & MK_SHIFT)) selStart = caret; } dragop = 0; if (GetFocus() != hWnd) SetFocus(hWnd); updateCaret(); } return 0; case WM_RBUTTONDOWN: if (int(GET_X_LPARAM(lParam)) >= int(settings->bpOffset - scrollPos.x * chSize.cx)) { POINT pt = paramToPoint(lParam); int offset = fromPoint(pt); int sela = (selStart < caret ? selStart : caret); int selb = (selStart > caret ? selStart : caret); if (offset < sela || offset >= selb) caret = selStart = offset; if (GetFocus() != hWnd) SetFocus(hWnd); updateCaret(); } return 0; case WM_MOUSEMOVE: if (GetCapture() == hWnd && (wParam & MK_LBUTTON)) { POINT pt = paramToPoint(lParam); caret = fromPoint(pt); updateCaret(); } return 0; case WM_LBUTTONUP: ReleaseCapture(); return 0; case WM_CHAR: if (iswprint(wParam) && (GetAsyncKeyState(VK_CONTROL) & 0x8000) == 0) { if (caret == selStart && !insertMode && caret < getTextLength()) replace(caret, caret + 1, WideString((wchar_t) wParam)); else replace(selStart, caret, WideString((wchar_t) wParam)); } return 0; case WM_VSCROLL: { SCROLLINFO si; memset(&si, 0, sizeof si); si.cbSize = sizeof si; si.fMask = SIF_ALL; GetScrollInfo(hWnd, SB_VERT, &si); switch (LOWORD(wParam)) { case SB_TOP: si.nPos = si.nMin; break; case SB_BOTTOM: si.nPos = si.nMax; break; case SB_LINEUP: si.nPos--; break; case SB_LINEDOWN: si.nPos++; break; case SB_PAGEUP: si.nPos -= si.nPage; break; case SB_PAGEDOWN: si.nPos += si.nPage; break; case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; } doScroll(scrollPos.x, si.nPos); } return 0; case WM_HSCROLL: { SCROLLINFO si; memset(&si, 0, sizeof si); si.cbSize = sizeof si; si.fMask = SIF_ALL; GetScrollInfo(hWnd, SB_HORZ, &si); switch (LOWORD(wParam)) { case SB_LEFT: si.nPos = si.nMin; break; case SB_RIGHT: si.nPos = si.nMax; break; case SB_LINELEFT: si.nPos--; break; case SB_LINERIGHT: si.nPos++; break; case SB_PAGELEFT: si.nPos -= si.nPage; break; case SB_PAGERIGHT: si.nPos += si.nPage; break; case SB_THUMBTRACK: si.nPos = si.nTrackPos; break; } doScroll(si.nPos, scrollPos.y); } return 0; case WM_MOUSEWHEEL: { int step; SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &step, 0); if (step < 0) step = 3; scrollAccum.y += GET_WHEEL_DELTA_WPARAM(wParam) * step; doScroll(scrollPos.x, scrollPos.y - scrollAccum.y / WHEEL_DELTA); scrollAccum.y %= WHEEL_DELTA; } return 0; case WM_MOUSEHWHEEL: { scrollAccum.x += GET_WHEEL_DELTA_WPARAM(wParam) * 4; doScroll(scrollPos.x + scrollAccum.x / WHEEL_DELTA, scrollPos.y); scrollAccum.x %= WHEEL_DELTA; } return 0; case WM_DRAGOVER: { if (running || settings->mode) return TRUE; POINT pt = paramToPoint(lParam); dropPos = fromPoint(pt); RECT rc; GetClientRect(hWnd, &rc); int xto = scrollPos.x; if (pt.x < 10) xto--; else if (pt.x > rc.right - 10) xto++; int yto = scrollPos.y; if (pt.y < 10) yto--; else if (pt.y > rc.bottom - 10) yto++; doScroll(xto, yto); int sela = (selStart < caret ? selStart : caret); int selb = (selStart > caret ? selStart : caret); if (dropPos > sela && dropPos < selb) return TRUE; else { fixPoint(pt); CreateCaret(hWnd, NULL, 2, chSize.cy); SetCaretPos((pt.x - scrollPos.x) * chSize.cx + LeftMargin(), (pt.y - scrollPos.y) * chSize.cy); ShowCaret(hWnd); } } return 0; case WM_DRAGLEAVE: dropPos = 0; updateCaret(); return 0; case WM_DRAGDROP: if (running || settings->mode) return DROPEFFECT_NONE; if (dragop) { dragop = 2; int sela = (selStart < caret ? selStart : caret); int selb = (selStart > caret ? selStart : caret); if (dropPos < sela || dropPos > selb) { WideString text = getSelection(); if (lParam != DROPEFFECT_COPY) { replace(sela, selb, L""); if (dropPos > selb) dropPos -= (selb - sela); caret = replace(dropPos, dropPos, text, NULL, true); } else caret = replace(dropPos, dropPos, text); selStart = dropPos; } } else { caret = replace(dropPos, dropPos, GetGlobalTextWide((HGLOBAL) wParam)); selStart = dropPos; return DROPEFFECT_COPY; } return lParam; case WM_SYSKEYDOWN: case WM_KEYDOWN: onKey(wParam); return 0; case WM_COMMAND: switch (LOWORD(wParam)) { case ID_EDIT_UNDO: { bool glue = true; bool first = true; while (glue && historyPos > 0) { HistoryItem& h = history[--historyPos]; replace(h.begin, h.end, h.text, &h); glue = h.glue; h.glue = !first; first = false; } } break; case ID_EDIT_REDO: { bool glue = true; bool first = true; while (glue && historyPos < history.length()) { HistoryItem& h = history[historyPos++]; replace(h.begin, h.end, h.text, &h); glue = h.glue; h.glue = !first; first = false; } } break; case ID_EDIT_SELECTALL: selStart = 0; caret = getTextLength(); updateCaret(); break; case ID_EDIT_COPY: if (caret != selStart) SetClipboard(CF_UNICODETEXT, CreateGlobalText(getSelection())); else { POINT pt = toPoint(caret); pt.x = 0; int start = fromPoint(pt); if (pt.y < lines.length() - 1) pt.y++; else pt.x = lines[pt.y].text.length(); int end = fromPoint(pt); if (pCopyLine) pCopyLine->Release(); pCopyLine = SetClipboard(CF_UNICODETEXT, CreateGlobalText(substring(start, end))); if (pCopyLine) pCopyLine->AddRef(); } break; case ID_EDIT_CUT: if (caret != selStart) { SetClipboard(CF_UNICODETEXT, CreateGlobalText(getSelection())); replace(selStart, caret, L""); } else { POINT pt = toPoint(caret); POINT save = pt; pt.x = 0; int start = fromPoint(pt); if (pt.y < lines.length() - 1) pt.y++; else pt.x = lines[pt.y].text.length(); int end = fromPoint(pt); if (pCopyLine) pCopyLine->Release(); pCopyLine = SetClipboard(CF_UNICODETEXT, CreateGlobalText(substring(start, end))); if (pCopyLine) pCopyLine->AddRef(); replace(start, end, L""); caret = selStart = fromPoint(save); updateCaret(); } break; case ID_EDIT_PASTE: { ClipboardReader reader(CF_UNICODETEXT); if (reader.getData()) { if (OleIsCurrentClipboard(pCopyLine) == S_OK) { POINT pt = toPoint(caret); pt.x = 0; caret = selStart = fromPoint(pt); } selStart = caret = replace(selStart, caret, GetGlobalTextWide(reader.getData())); updateCaret(); } } break; case ID_DEBUG_BREAKPOINT: { POINT pt = toPoint(caret); toggleBreakpoint(pt.y); } break; default: return M_UNHANDLED; } return 0; } return M_UNHANDLED; }
void GUIElement::OnKey(char x) { if(onKey != NULL) { return onKey(this, x); } std::cout << "You hit me with: " << x ; }
void Player::keyPressEvent(QKeyEvent *event) { //qDebug() << (uint) event->key(); // чтобы узнать код клавиши //qDebug() << event->text(); if (alive) { switch ((uint) event->key()) { // Двигаться вперед case 87: // W case 1062: // Ц case 16777235: // Up mf = true; break; // Двигаться назад case 83: // S case 1067: // Ы case 16777237: // Down mb = true; break; // Поворот танка налево case 65: // A case 1060: // Ф case 16777234: // Left rl = true; break; // Поворот танка направо case 68: // D case 1042: // В case 16777236: // Right rr = true; break; // Поворот башни налево case 81: // Q case 1049: // Й case 90: // Z case 1071: // Я hl = true; break; // Поворот башни направо case 69: // E case 1059: // У case 88: // X case 1063: // Ч hr = true; break; // Выстрел case 32: // SPAAAAACE fr = true; break; // Меню case 16777216: // Esc //ingame = false; emit tomenu(); break; // Таблица case 96: // ` case 1025: // ё //qDebug() << "score"; break; // цифры (для тестов) case 49: //this->changeSize(pixsize-10); //qDebug() << pixsize; break; case 50: //this->changeSize(pixsize+10); //qDebug() << pixsize; break; case 51: //randomSpawn(); break; case 52: //qDebug() << QSysInfo::kernelType(); break; case 53: //getDmg(10); //last = QTime::currentTime(); break; case 54: //qDebug() << cur.minute() << " " << cur.second() << " " << cur.msec(); //qDebug() << last.msecsTo(QTime::currentTime()); break; } if (action == false) { if (alive) { action = true; onKey(); } } //game->health->setPos(game->player->x()+40,game->player->y()+50); } }
void COSXScreen::handleSystemEvent(const CEvent& event, void*) { EventRef* carbonEvent = reinterpret_cast<EventRef*>(event.getData()); assert(carbonEvent != NULL); UInt32 eventClass = GetEventClass(*carbonEvent); switch (eventClass) { case kEventClassMouse: switch (GetEventKind(*carbonEvent)) { case kEventMouseDown: { UInt16 myButton; GetEventParameter(*carbonEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof(myButton), NULL, &myButton); onMouseButton(true, myButton); break; } case kEventMouseUp: { UInt16 myButton; GetEventParameter(*carbonEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof(myButton), NULL, &myButton); onMouseButton(false, myButton); break; } case kEventMouseDragged: case kEventMouseMoved: { HIPoint point; GetEventParameter(*carbonEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(point), NULL, &point); onMouseMove((SInt32)point.x, (SInt32)point.y); break; } case kEventMouseWheelMoved: { EventMouseWheelAxis axis; SInt32 delta; GetEventParameter(*carbonEvent, kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL, sizeof(axis), NULL, &axis); if (axis == kEventMouseWheelAxisX || axis == kEventMouseWheelAxisY) { GetEventParameter(*carbonEvent, kEventParamMouseWheelDelta, typeLongInteger, NULL, sizeof(delta), NULL, &delta); if (axis == kEventMouseWheelAxisX) { onMouseWheel(-mapScrollWheelToSynergy((SInt32)delta), 0); } else { onMouseWheel(0, mapScrollWheelToSynergy((SInt32)delta)); } } break; } case kSynergyEventMouseScroll: { OSStatus r; long xScroll; long yScroll; // get scroll amount r = GetEventParameter(*carbonEvent, kSynergyMouseScrollAxisX, typeLongInteger, NULL, sizeof(xScroll), NULL, &xScroll); if (r != noErr) { xScroll = 0; } r = GetEventParameter(*carbonEvent, kSynergyMouseScrollAxisY, typeLongInteger, NULL, sizeof(yScroll), NULL, &yScroll); if (r != noErr) { yScroll = 0; } if (xScroll != 0 || yScroll != 0) { onMouseWheel(-mapScrollWheelToSynergy(xScroll), mapScrollWheelToSynergy(yScroll)); } } } break; case kEventClassKeyboard: switch (GetEventKind(*carbonEvent)) { case kEventRawKeyUp: case kEventRawKeyDown: case kEventRawKeyRepeat: case kEventRawKeyModifiersChanged: onKey(*carbonEvent); break; case kEventHotKeyPressed: case kEventHotKeyReleased: onHotKey(*carbonEvent); break; } break; case kEventClassWindow: SendEventToWindow(*carbonEvent, m_userInputWindow); switch (GetEventKind(*carbonEvent)) { case kEventWindowActivated: LOG((CLOG_DEBUG1 "window activated")); break; case kEventWindowDeactivated: LOG((CLOG_DEBUG1 "window deactivated")); break; case kEventWindowFocusAcquired: LOG((CLOG_DEBUG1 "focus acquired")); break; case kEventWindowFocusRelinquish: LOG((CLOG_DEBUG1 "focus released")); break; } break; default: SendEventToEventTarget(*carbonEvent, GetEventDispatcherTarget()); break; } }