예제 #1
0
파일: __init__.py 프로젝트: sangh/LaserShow
    def _event_text_symbol(self, ev):
        text = None
        symbol = xlib.KeySym()
        buffer = create_string_buffer(128)

        # Look up raw keysym before XIM filters it (default for keypress and
        # keyrelease)
        count = xlib.XLookupString(ev.xkey, buffer, len(buffer) - 1, byref(symbol), None)

        # Give XIM a shot
        filtered = xlib.XFilterEvent(ev, ev.xany.window)

        if ev.type == xlib.KeyPress and not filtered:
            status = c_int()
            if _have_utf8:
                encoding = "utf8"
                count = xlib.Xutf8LookupString(
                    self._x_ic, ev.xkey, buffer, len(buffer) - 1, byref(symbol), byref(status)
                )
                if status.value == xlib.XBufferOverflow:
                    raise NotImplementedError("TODO: XIM buffer resize")

            else:
                encoding = "ascii"
                count = xlib.XLookupString(ev.xkey, buffer, len(buffer) - 1, byref(symbol), None)
                if count:
                    status.value = xlib.XLookupBoth

            if status.value & (xlib.XLookupChars | xlib.XLookupBoth):
                text = buffer.value[:count].decode(encoding)

            # Don't treat Unicode command codepoints as text, except Return.
            if text and unicodedata.category(text) == "Cc" and text != "\r":
                text = None

        symbol = symbol.value

        # If the event is a XIM filtered event, the keysym will be virtual
        # (e.g., aacute instead of A after a dead key).  Drop it, we don't
        # want these kind of key events.
        if ev.xkey.keycode == 0 and not filtered:
            symbol = None

        # pyglet.self.key keysymbols are identical to X11 keysymbols, no
        # need to map the keysymbol.  For keysyms outside the pyglet set, map
        # raw key code to a user key.
        if symbol and symbol not in key._key_names and ev.xkey.keycode:
            # Issue 353: Symbol is uppercase when shift key held down.
            symbol = ord(unichr(symbol).lower())

            # If still not recognised, use the keycode
            if symbol not in key._key_names:
                symbol = key.user_key(ev.xkey.keycode)

        if filtered:
            # The event was filtered, text must be ignored, but the symbol is
            # still good.
            return None, symbol

        return text, symbol
예제 #2
0
 def _event_symbol(self, event):
     # pyglet.self.key keysymbols are identical to X11 keysymbols, no
     # need to map the keysymbol.
     symbol = xlib.XKeycodeToKeysym(self._x_display, event.xkey.keycode, 0)
     if symbol not in key._key_names.keys():
         symbol = key.user_key(event.xkey.keycode)
     return symbol
예제 #3
0
파일: __init__.py 프로젝트: ajhager/copycat
 def _get_symbol_and_modifiers(ev):
     # The unicode char help processing virtual keycodes (see issue 405)
     wchar = c_wchar()
     carbon.GetEventParameter(ev, kEventParamKeyUnicodes,
         typeUnicodeText, c_void_p(), sizeof(wchar), c_void_p(), byref(wchar))
     try:
         wchar = str((wchar.value)).upper()
     except UnicodeEncodeError:
         # (this fix for issue 405 caused a bug itself (see comments 6-7);
         #  this try/except fixes it)
         wchar = None
     # If the unicode char is within charmap keys (ascii value), then we use
     # the corresponding symbol.
     if wchar in charmap.keys():
         symbol = charmap[wchar]
     else:
         sym = c_uint32()
         carbon.GetEventParameter(ev, kEventParamKeyCode,
                                  typeUInt32, c_void_p(), sizeof(sym), c_void_p(), byref(sym))
         symbol = keymap.get(sym.value, None)
         if symbol is None:
             symbol = key.user_key(sym.value)
     modifiers = c_uint32()
     carbon.GetEventParameter(ev, kEventParamKeyModifiers,
         typeUInt32, c_void_p(), sizeof(modifiers), c_void_p(),
         byref(modifiers))
     return (symbol, CarbonWindow._map_modifiers(modifiers.value))
예제 #4
0
 def _get_symbol_and_modifiers(ev):
     # The unicode char help processing virtual keycodes (see issue 405)
     wchar = c_wchar()
     carbon.GetEventParameter(ev, kEventParamKeyUnicodes,
         typeUnicodeText, c_void_p(), sizeof(wchar), c_void_p(), byref(wchar))
     try:
         wchar = str((wchar.value)).upper()
     except UnicodeEncodeError:
         # (this fix for issue 405 caused a bug itself (see comments 6-7);
         #  this try/except fixes it)
         wchar = None
     # If the unicode char is within charmap keys (ascii value), then we use
     # the corresponding symbol.
     if wchar in charmap.keys():
         symbol = charmap[wchar]
     else:
         sym = c_uint32()
         carbon.GetEventParameter(ev, kEventParamKeyCode,
                                  typeUInt32, c_void_p(), sizeof(sym), c_void_p(), byref(sym))
         symbol = keymap.get(sym.value, None)
         if symbol is None:
             symbol = key.user_key(sym.value)
     modifiers = c_uint32()
     carbon.GetEventParameter(ev, kEventParamKeyModifiers,
         typeUInt32, c_void_p(), sizeof(modifiers), c_void_p(),
         byref(modifiers))
     return (symbol, CarbonWindow._map_modifiers(modifiers.value))
예제 #5
0
 def _event_symbol(self, event):
     # pyglet.self.key keysymbols are identical to X11 keysymbols, no
     # need to map the keysymbol.
     symbol = xlib.XKeycodeToKeysym(self._x_display, event.xkey.keycode, 0)
     if symbol not in key._key_names.keys():
         symbol = key.user_key(event.xkey.keycode)
     return symbol
예제 #6
0
 def get_key_value(self, value):
     try:
         int(value)
         value = '_' + value
     except ValueError:
         pass
     if value.startswith('userkey('):
         value = value.replace('userkey(', '').replace(')', '')
         return key.user_key(int(value, 16))
     return getattr(key, value)
예제 #7
0
 def OnKeyDown(self, event):
     kc = event.GetKeyCode()        
     symbol = keymap.get(kc, None)
     if symbol is None:
         ch = kc #???
         symbol = chmap.get(ch)
     if symbol is None:
         symbol = key.user_key(wParam)
     modifiers = 0
     self.dispatch_event('on_key_press', symbol, modifiers)
 def get_key_value(self, value):
     try:
         int(value)
         value = '_' + value
     except ValueError:
         pass
     if value.startswith('userkey('):
         value = value.replace('userkey(', '').replace(')', '')
         return key.user_key(int(value, 16))
     return getattr(key, value)
예제 #9
0
    def _get_symbol_and_modifiers(ev):
        sym = c_uint32()
        carbon.GetEventParameter(ev, kEventParamKeyCode, typeUInt32, c_void_p(), sizeof(sym), c_void_p(), byref(sym))
        modifiers = c_uint32()
        carbon.GetEventParameter(
            ev, kEventParamKeyModifiers, typeUInt32, c_void_p(), sizeof(modifiers), c_void_p(), byref(modifiers)
        )

        symbol = keymap.get(sym.value, None)
        if symbol is None:
            symbol = key.user_key(sym.value)

        return (symbol, CarbonWindow._map_modifiers(modifiers.value))
예제 #10
0
    def _get_symbol_and_modifiers(ev):
        sym = c_uint32()
        carbon.GetEventParameter(ev, kEventParamKeyCode,
            typeUInt32, c_void_p(), sizeof(sym), c_void_p(), byref(sym))
        modifiers = c_uint32()
        carbon.GetEventParameter(ev, kEventParamKeyModifiers,
            typeUInt32, c_void_p(), sizeof(modifiers), c_void_p(),
            byref(modifiers))

        symbol = keymap.get(sym.value, None)
        if symbol is None:
            symbol = key.user_key(sym.value)

        return (symbol, CarbonWindow._map_modifiers(modifiers.value))
예제 #11
0
파일: __init__.py 프로젝트: momja/Code-Club
    def _event_key(self, msg, wParam, lParam):
        repeat = False
        if lParam & (1 << 30):
            if msg not in (WM_KEYUP, WM_SYSKEYUP):
                repeat = True
            ev = 'on_key_release'
        else:
            ev = 'on_key_press'

        symbol = keymap.get(wParam, None)
        if symbol is None:
            ch = _user32.MapVirtualKeyW(wParam, MAPVK_VK_TO_CHAR)
            symbol = chmap.get(ch)

        if symbol is None:
            symbol = key.user_key(wParam)
        elif symbol == key.LCTRL and lParam & (1 << 24):
            symbol = key.RCTRL
        elif symbol == key.LALT and lParam & (1 << 24):
            symbol = key.RALT
        elif symbol == key.LSHIFT:
            pass  # TODO: some magic with getstate to find out if it's the
            # right or left shift key.

        modifiers = self._get_modifiers(lParam)

        if not repeat:
            self.dispatch_event(ev, symbol, modifiers)

        ctrl = modifiers & key.MOD_CTRL != 0
        if (symbol, ctrl) in _motion_map and msg not in (WM_KEYUP,
                                                         WM_SYSKEYUP):
            motion = _motion_map[symbol, ctrl]
            if modifiers & key.MOD_SHIFT:
                self.dispatch_event('on_text_motion_select', motion)
            else:
                self.dispatch_event('on_text_motion', motion)

        # Send on to DefWindowProc if not exclusive.
        if self._exclusive_keyboard:
            return 0
        else:
            return None
예제 #12
0
    def _event_key(self, msg, wParam, lParam):
        repeat = False
        if lParam & (1 << 30):
            if msg not in (WM_KEYUP, WM_SYSKEYUP):
                repeat = True
            ev = 'on_key_release'
        else:
            ev = 'on_key_press'

        symbol = keymap.get(wParam, None)
        if symbol is None:
            ch = _user32.MapVirtualKeyW(wParam, MAPVK_VK_TO_CHAR)
            symbol = chmap.get(ch)

        if symbol is None:
            symbol = key.user_key(wParam)
        elif symbol == key.LCTRL and lParam & (1 << 24):
            symbol = key.RCTRL
        elif symbol == key.LALT and lParam & (1 << 24):
            symbol = key.RALT

        if wParam == VK_SHIFT:
            return  # Let raw input handle this instead.

        modifiers = self._get_modifiers(lParam)

        if not repeat:
            self.dispatch_event(ev, symbol, modifiers)

        ctrl = modifiers & key.MOD_CTRL != 0
        if (symbol, ctrl) in _motion_map and msg not in (WM_KEYUP,
                                                         WM_SYSKEYUP):
            motion = _motion_map[symbol, ctrl]
            if modifiers & key.MOD_SHIFT:
                self.dispatch_event('on_text_motion_select', motion)
            else:
                self.dispatch_event('on_text_motion', motion)

        # Send on to DefWindowProc if not exclusive.
        if self._keyboard_exclusive:
            return 0
        else:
            return None
예제 #13
0
    def _event_key(self, msg, wParam, lParam):
        repeat = False
        if lParam & (1 << 30):
            if msg not in (WM_KEYUP, WM_SYSKEYUP):
                repeat = True
            ev = 'on_key_release'
        else:
            ev = 'on_key_press'

        symbol = keymap.get(wParam, None)
        if symbol is None:
            ch = _user32.MapVirtualKeyW(wParam, MAPVK_VK_TO_CHAR)
            symbol = chmap.get(ch)

        if symbol is None:
            symbol = key.user_key(wParam)
        elif symbol == key.LCTRL and lParam & (1 << 24):
            symbol = key.RCTRL
        elif symbol == key.LALT and lParam & (1 << 24):
            symbol = key.RALT
        elif symbol == key.LSHIFT:
            pass # TODO: some magic with getstate to find out if it's the
                 # right or left shift key. 

        modifiers = self._get_modifiers(lParam)
        
        if not repeat:
            self.dispatch_event(ev, symbol, modifiers)

        ctrl = modifiers & key.MOD_CTRL != 0
        if (symbol, ctrl) in _motion_map and msg not in (WM_KEYUP, WM_SYSKEYUP):
            motion = _motion_map[symbol, ctrl]
            if modifiers & key.MOD_SHIFT:
                self.dispatch_event('on_text_motion_select', motion)
            else:
                self.dispatch_event('on_text_motion', motion)

        # Send on to DefWindowProc if not exclusive.
        if self._exclusive_keyboard:
            return 0
        else:
            return None
예제 #14
0
    def _event_text_symbol(self, ev):
        text = None
        symbol = xlib.KeySym()
        buffer = create_string_buffer(128)

        # Look up raw keysym before XIM filters it (default for keypress and
        # keyrelease)
        count = xlib.XLookupString(ev.xkey,
                                   buffer, len(buffer) - 1,
                                   byref(symbol), None)

        # Give XIM a shot
        filtered = xlib.XFilterEvent(ev, ev.xany.window)

        if ev.type == xlib.KeyPress and not filtered:
            status = c_int()
            if _have_utf8:
                encoding = 'utf8'
                count = xlib.Xutf8LookupString(self._x_ic,
                                               ev.xkey,
                                               buffer, len(buffer) - 1,
                                               byref(symbol), byref(status))
                if status.value == xlib.XBufferOverflow:
                    raise NotImplementedError('TODO: XIM buffer resize')

            else:
                encoding = 'ascii'
                count = xlib.XLookupString(ev.xkey,
                                           buffer, len(buffer) - 1,
                                           byref(symbol), None)
                if count:
                    status.value = xlib.XLookupBoth

            if status.value & (xlib.XLookupChars | xlib.XLookupBoth):
                text = buffer.value[:count].decode(encoding)

            # Don't treat Unicode command codepoints as text, except Return.
            if text and unicodedata.category(text) == 'Cc' and text != '\r':
                text = None

        symbol = symbol.value

        # If the event is a XIM filtered event, the keysym will be virtual
        # (e.g., aacute instead of A after a dead key).  Drop it, we don't
        # want these kind of key events.
        if ev.xkey.keycode == 0 and not filtered:
            symbol = None

        # pyglet.self.key keysymbols are identical to X11 keysymbols, no
        # need to map the keysymbol.  For keysyms outside the pyglet set, map
        # raw key code to a user key.
        if symbol and symbol not in key._key_names and ev.xkey.keycode:
            # Issue 353: Symbol is uppercase when shift key held down.
            symbol = ord(unichr(symbol).lower())

            # If still not recognised, use the keycode
            if symbol not in key._key_names:
                symbol = key.user_key(ev.xkey.keycode)

        if filtered:
            # The event was filtered, text must be ignored, but the symbol is
            # still good.
            return None, symbol

        return text, symbol