void getModifierState(bool &shiftDown, bool &controlDown, bool &altDown) { UInt32 modKeys = GetCurrentEventKeyModifiers(); shiftDown = (modKeys & shiftKey) != 0; controlDown = (modKeys & controlKey) != 0; altDown = (modKeys & optionKey) != 0; }
int TkMacOSXProcessCommandEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) { HICommand command; int menuContext; OSStatus status; switch (eventPtr->eKind) { case kEventCommandProcess: case kEventCommandUpdateStatus: break; default: return 0; break; } status = GetEventParameter(eventPtr->eventRef, kEventParamDirectObject, typeHICommand, NULL, sizeof(command), NULL, &command); if (status == noErr && (command.attributes & kHICommandFromMenu)) { if (eventPtr->eKind == kEventCommandProcess) { status = GetEventParameter(eventPtr->eventRef, kEventParamMenuContext, typeUInt32, NULL, sizeof(menuContext), NULL, &menuContext); if (status == noErr && (menuContext & kMenuContextMenuBar) && (menuContext & kMenuContextMenuBarTracking)) { TkMacOSXHandleMenuSelect(GetMenuID(command.menu.menuRef), command.menu.menuItemIndex, GetCurrentEventKeyModifiers() & optionKey); return 1; } } else { Tcl_CmdInfo dummy; if (command.commandID == kHICommandPreferences && eventPtr->interp) { if (Tcl_GetCommandInfo(eventPtr->interp, "::tk::mac::ShowPreferences", &dummy)) { if (!IsMenuItemEnabled(command.menu.menuRef, command.menu.menuItemIndex)) { EnableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); } } else { if (IsMenuItemEnabled(command.menu.menuRef, command.menu.menuItemIndex)) { DisableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); } } return 1; } } } return 0; }
EventModifiers TkMacOSXModifierState(void) { UInt32 keyModifiers; int isFrontProcess = (GetCurrentEvent() && Tk_MacOSXIsAppInFront()); keyModifiers = isFrontProcess ? GetCurrentEventKeyModifiers() : GetCurrentKeyModifiers(); return (EventModifiers)(keyModifiers & USHRT_MAX); }
unsigned int TkMacOSXButtonKeyState(void) { UInt32 buttonState = 0, keyModifiers; int isFrontProcess = (GetCurrentEvent() && Tk_MacOSXIsAppInFront()); if (!TkMacOSXGetEatButtonUp()) { buttonState = isFrontProcess ? GetCurrentEventButtonState() : GetCurrentButtonState(); } keyModifiers = isFrontProcess ? GetCurrentEventKeyModifiers() : GetCurrentKeyModifiers(); return ButtonModifiers2State(buttonState, keyModifiers); }
MASK LLKeyboardMacOSX::currentMask(BOOL for_mouse_event) { MASK result = MASK_NONE; U32 mask = GetCurrentEventKeyModifiers(); if (mask & shiftKey) result |= MASK_SHIFT; if (mask & controlKey) result |= MASK_CONTROL; if (mask & optionKey) result |= MASK_ALT; // For keyboard events, consider Command equivalent to Control if (!for_mouse_event) { if (mask & cmdKey) result |= MASK_CONTROL; } return result; }
int RocketFrameListener::GetKeyModifierState() { int modifier_state = 0; if (mKeyboard->isModifierDown(OIS::Keyboard::Ctrl)) modifier_state |= Rocket::Core::Input::KM_CTRL; if (mKeyboard->isModifierDown(OIS::Keyboard::Shift)) modifier_state |= Rocket::Core::Input::KM_SHIFT; if (mKeyboard->isModifierDown(OIS::Keyboard::Alt)) modifier_state |= Rocket::Core::Input::KM_ALT; #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 if (GetKeyState(VK_CAPITAL) > 0) modifier_state |= Rocket::Core::Input::KM_CAPSLOCK; if (GetKeyState(VK_NUMLOCK) > 0) modifier_state |= Rocket::Core::Input::KM_NUMLOCK; if (GetKeyState(VK_SCROLL) > 0) modifier_state |= Rocket::Core::Input::KM_SCROLLLOCK; #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE UInt32 key_modifiers = GetCurrentEventKeyModifiers(); if (key_modifiers & (1 << alphaLockBit)) modifier_state |= Rocket::Core::Input::KM_CAPSLOCK; #elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX XKeyboardState keyboard_state; XGetKeyboardControl(DISPLAY!, &keyboard_state); if (keyboard_state.led_mask & (1 << 0)) modifier_state |= Rocket::Core::Input::KM_CAPSLOCK; if (keyboard_state.led_mask & (1 << 1)) modifier_state |= Rocket::Core::Input::KM_NUMLOCK; if (keyboard_state.led_mask & (1 << 2)) modifier_state |= Rocket::Core::Input::KM_SCROLLLOCK; #endif return modifier_state; }
void LLKeyboardMacOSX::resetMaskKeys() { U32 mask = GetCurrentEventKeyModifiers(); // MBW -- XXX -- This mirrors the operation of the Windows version of resetMaskKeys(). // It looks a bit suspicious, as it won't correct for keys that have been released. // Is this the way it's supposed to work? if(mask & shiftKey) { mKeyLevel[KEY_SHIFT] = TRUE; } if(mask & (controlKey)) { mKeyLevel[KEY_CONTROL] = TRUE; } if(mask & optionKey) { mKeyLevel[KEY_ALT] = TRUE; } }
static bool translateKeyEventInternal(EventHandlerCallRef er, EventRef keyEvent, int *qtKey, QChar *outChar, Qt::KeyboardModifiers *outModifiers, bool *outHandled) { #if !defined(QT_MAC_USE_COCOA) || defined(Q_OS_MAC64) Q_UNUSED(er); Q_UNUSED(outHandled); #endif const UInt32 ekind = GetEventKind(keyEvent); { UInt32 mac_modifiers = 0; GetEventParameter(keyEvent, kEventParamKeyModifiers, typeUInt32, 0, sizeof(mac_modifiers), 0, &mac_modifiers); #ifdef DEBUG_KEY_BINDINGS_MODIFIERS qDebug("************ Mapping modifiers and key ***********"); #endif *outModifiers = qt_mac_get_modifiers(mac_modifiers); #ifdef DEBUG_KEY_BINDINGS_MODIFIERS qDebug("------------ Mapping modifiers and key -----------"); #endif } //get keycode UInt32 keyCode = 0; GetEventParameter(keyEvent, kEventParamKeyCode, typeUInt32, 0, sizeof(keyCode), 0, &keyCode); //get mac mapping static UInt32 tmp_unused_state = 0L; const UCKeyboardLayout *uchrData = 0; #if defined(Q_OS_MAC32) KeyboardLayoutRef keyLayoutRef = 0; KLGetCurrentKeyboardLayout(&keyLayoutRef); OSStatus err; if (keyLayoutRef != 0) { err = KLGetKeyboardLayoutProperty(keyLayoutRef, kKLuchrData, (reinterpret_cast<const void **>(&uchrData))); if (err != noErr) { qWarning("Qt::internal::unable to get keyboardlayout %ld %s:%d", long(err), __FILE__, __LINE__); } } #else QCFType<TISInputSourceRef> inputSource = TISCopyCurrentKeyboardInputSource(); Q_ASSERT(inputSource != 0); CFDataRef data = static_cast<CFDataRef>(TISGetInputSourceProperty(inputSource, kTISPropertyUnicodeKeyLayoutData)); uchrData = data ? reinterpret_cast<const UCKeyboardLayout *>(CFDataGetBytePtr(data)) : 0; #endif *qtKey = Qt::Key_unknown; if (uchrData) { // The easy stuff; use the unicode stuff! UniChar string[4]; UniCharCount actualLength; UInt32 currentModifiers = GetCurrentEventKeyModifiers(); UInt32 currentModifiersWOAltOrControl = currentModifiers & ~(controlKey | optionKey); int keyAction; switch (ekind) { default: case kEventRawKeyDown: keyAction = kUCKeyActionDown; break; case kEventRawKeyUp: keyAction = kUCKeyActionUp; break; case kEventRawKeyRepeat: keyAction = kUCKeyActionAutoKey; break; } OSStatus err = UCKeyTranslate(uchrData, keyCode, keyAction, ((currentModifiersWOAltOrControl >> 8) & 0xff), LMGetKbdType(), kUCKeyTranslateNoDeadKeysMask, &tmp_unused_state, 4, &actualLength, string); if (err == noErr) { *outChar = QChar(string[0]); *qtKey = qt_mac_get_key(*outModifiers, *outChar, keyCode); if (currentModifiersWOAltOrControl != currentModifiers) { // Now get the real char. err = UCKeyTranslate(uchrData, keyCode, keyAction, ((currentModifiers >> 8) & 0xff), LMGetKbdType(), kUCKeyTranslateNoDeadKeysMask, &tmp_unused_state, 4, &actualLength, string); if (err == noErr) *outChar = QChar(string[0]); } } else {
MODULE_SCOPE int TkMacOSXProcessMouseEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) { Tk_Window tkwin; Point where, where2; int result; TkDisplay * dispPtr; OSStatus err; MouseEventData mouseEventData, * medPtr = &mouseEventData; int isFrontProcess; switch (eventPtr->eKind) { case kEventMouseDown: case kEventMouseUp: case kEventMouseMoved: case kEventMouseDragged: case kEventMouseWheelMoved: break; default: return false; break; } err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(where), NULL, &where); if (err != noErr) { GetGlobalMouse(&where); } err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamWindowRef, typeWindowRef, NULL, sizeof(WindowRef), NULL, &medPtr->whichWin); if (err == noErr) { err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamWindowPartCode, typeWindowPartCode, NULL, sizeof(WindowPartCode), NULL, &medPtr->windowPart); } if (err != noErr) { medPtr->windowPart = FindWindow(where, &medPtr->whichWin); } medPtr->window = TkMacOSXGetXWindow(medPtr->whichWin); if (medPtr->whichWin != NULL && medPtr->window == None) { return false; } if (eventPtr->eKind == kEventMouseDown) { if (IsWindowActive(medPtr->whichWin) && IsWindowPathSelectEvent( medPtr->whichWin, eventPtr->eventRef)) { ChkErr(WindowPathSelect, medPtr->whichWin, NULL, NULL); return false; } if (medPtr->windowPart == inProxyIcon) { TkMacOSXTrackingLoop(1); err = ChkErr(TrackWindowProxyDrag, medPtr->whichWin, where); TkMacOSXTrackingLoop(0); if (err == errUserWantsToDragWindow) { medPtr->windowPart = inDrag; } else { return false; } } } isFrontProcess = Tk_MacOSXIsAppInFront(); if (isFrontProcess) { medPtr->state = ButtonModifiers2State(GetCurrentEventButtonState(), GetCurrentEventKeyModifiers()); } else { medPtr->state = ButtonModifiers2State(GetCurrentButtonState(), GetCurrentKeyModifiers()); } medPtr->global = where; err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamWindowMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &medPtr->local); if (err == noErr) { if (medPtr->whichWin) { Rect widths; GetWindowStructureWidths(medPtr->whichWin, &widths); medPtr->local.h -= widths.left; medPtr->local.v -= widths.top; } } else { medPtr->local = where; if (medPtr->whichWin) { QDGlobalToLocalPoint(GetWindowPort(medPtr->whichWin), &medPtr->local); } } medPtr->activeNonFloating = ActiveNonFloatingWindow(); dispPtr = TkGetDisplayList(); tkwin = Tk_IdToWindow(dispPtr->display, medPtr->window); if (eventPtr->eKind != kEventMouseDown) { int res = false; switch (eventPtr->eKind) { case kEventMouseUp: /* * The window manager only needs to know about mouse down * events and sometimes we need to "eat" the mouse up. * Otherwise, we just pass the event to Tk. */ if (TkMacOSXGetEatButtonUp()) { TkMacOSXSetEatButtonUp(false); } else { res = GenerateButtonEvent(medPtr); } break; case kEventMouseWheelMoved: err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamMouseWheelDelta, typeLongInteger, NULL, sizeof(long), NULL, &medPtr->delta); if (err != noErr ) { statusPtr->err = 1; } else { EventMouseWheelAxis axis; err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL, sizeof(EventMouseWheelAxis), NULL, &axis); if (err == noErr && axis == kEventMouseWheelAxisX) { medPtr->state |= ShiftMask; } res = GenerateMouseWheelEvent(medPtr); } break; case kEventMouseMoved: case kEventMouseDragged: res = GeneratePollingEvents(medPtr); break; default: Tcl_Panic("Unknown mouse event !"); } if (res) { statusPtr->stopProcessing = 1; } return res; } TkMacOSXSetEatButtonUp(false); if (medPtr->whichWin) { /* * We got a mouse down in a window * See if this is the activate click * This click moves the window forward. We don't want * the corresponding mouse-up to be reported to the application * or else it will mess up some Tk scripts. */ if (!(TkpIsWindowFloating(medPtr->whichWin)) && (medPtr->whichWin != medPtr->activeNonFloating || !isFrontProcess)) { int frontWindowOnly = 1; int cmdDragGrow = ((medPtr->windowPart == inDrag || medPtr->windowPart == inGrow) && medPtr->state & Mod1Mask); if (!cmdDragGrow) { Tk_Window grabWin = GetGrabWindowForWindow(tkwin); frontWindowOnly = !grabWin; if (grabWin && grabWin != tkwin) { TkMacOSXSetEatButtonUp(true); BringWindowForward(TkMacOSXDrawableWindow( ((TkWindow*)grabWin)->window), isFrontProcess, frontWindowOnly); return false; } } /* * Clicks in the titlebar widgets are handled without bringing the * window forward. */ if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) { statusPtr->stopProcessing = 1; return result; } else { /* * Only windows with the kWindowNoActivatesAttribute can * receive mouse events in the background. */ if (!(((TkWindow *)tkwin)->wmInfoPtr->attributes & kWindowNoActivatesAttribute)) { /* * Allow background window dragging & growing with Command * down. */ if (!cmdDragGrow) { TkMacOSXSetEatButtonUp(true); BringWindowForward(medPtr->whichWin, isFrontProcess, frontWindowOnly); } /* * Allow dragging & growing of windows that were/are in the * background. */ if (!(medPtr->windowPart == inDrag || medPtr->windowPart == inGrow)) { return false; } } } } else { if ((result = HandleWindowTitlebarMouseDown(medPtr, tkwin)) != -1) { statusPtr->stopProcessing = 1; return result; } } switch (medPtr->windowPart) { case inDrag: { WindowAttributes attributes; GetWindowAttributes(medPtr->whichWin, &attributes); if (!(attributes & kWindowAsyncDragAttribute)) { TkMacOSXTrackingLoop(1); DragWindow(medPtr->whichWin, where, NULL); TkMacOSXTrackingLoop(0); where2.h = where2.v = 0; QDLocalToGlobalPoint(GetWindowPort(medPtr->whichWin), &where2); if (EqualPt(where, where2)) { return false; } return true; } break; } case inGrow: /* * Generally the content region is the domain of Tk * sub-windows. However, one exception is the grow * region. A button down in this area will be handled * by the window manager. Note: this means that Tk * may not get button down events in this area! */ if (TkMacOSXGrowToplevel(medPtr->whichWin, where) == true) { statusPtr->stopProcessing = 1; return true; } else { return GenerateButtonEvent(medPtr); } break; case inContent: return GenerateButtonEvent(medPtr); break; default: return false; break; } } return false; }