Пример #1
0
def char_to_keycode(ch) :
	keysym = get_keysym(ch)
	keycode = display.keysym_to_keycode(keysym)
	keysym2=display.keycode_to_keysym(keycode,0)
	if keysym != keysym2 :
		return keycode , True
	else :
		return keycode , False
def char_to_keycode(ch):
    keysym = get_keysym(ch)
    keycode = display.keysym_to_keycode(keysym)
    keysym2 = display.keycode_to_keysym(keycode, 0)
    if keysym != keysym2:
        return keycode, True
    else:
        return keycode, False
Пример #3
0
    def handle_KeyPress(self, e):
        display = self.display
        keycode = display.keycode_to_keysym(e.detail ,0)

        action = self._actions.get(keycode)
        if action:
            print "ACTION", action
            getattr(self, action)()
        else:
            print "KEYCODE", keycode
Пример #4
0
    def _keycode_to_scan_code(self, display, keycode, index):
        scan_code = display.keycode_to_keysym(keycode, index)

        if scan_code:
            return scan_code
        elif index & 0x2:
            return self._keycode_to_scan_code(display, keycode, index & ~0x2)
        elif index & 0x1:
            return self._keycode_to_scan_code(display, keycode, index & ~0x1)
        else:
            return 0
Пример #5
0
def setup(ui_model):
    keymap_mgr = ui_model.get_keymap_manager()

    scancode_rows = _get_scancode_rows()

    # Scancodes
    scancode_locs = {}
    for row, codes in enumerate(scancode_rows):
        for index, code in enumerate(codes):
            scancode_locs[code] = (row, index)
    keymap_mgr.set_scancode_locations(scancode_locs)

    if _has_xlib:
        display = Xlib.display.Display()

        key_names = {}
        for row, codes in enumerate(scancode_rows):
            for index, code in enumerate(codes):
                keysym = display.keycode_to_keysym(code, 0)
                if keysym != Xlib.X.NoSymbol:
                    name = display.lookup_string(keysym)
                    if name:
                        key_names[(row, index)] = name.upper()

        display.close()

        keymap_mgr.set_key_names(key_names)

    # TODO: set key ID locations for systems that need them

    # Actions
    key_actions = {
        (0, 0): KeyboardAction(KeyboardAction.REST),
        (2, 9): KeyboardAction(KeyboardAction.OCTAVE_DOWN),
        (2, 10): KeyboardAction(KeyboardAction.OCTAVE_UP),
        (3, 7): KeyboardAction(KeyboardAction.PLAY),
        (3, 8): KeyboardAction(KeyboardAction.SILENCE),
    }
    tw_sizes = keymap_mgr.get_typewriter_row_sizes()
    tw_offsets = keymap_mgr.get_typewriter_row_offsets()
    for row, (size, offset) in enumerate(zip(tw_sizes, tw_offsets)):
        for index in range(size):
            loc = (row, index + offset)
            assert loc not in key_actions
            key_actions[loc] = KeyboardNoteAction(row, index)
    keymap_mgr.set_key_actions(key_actions)
Пример #6
0
def setup(ui_model):
    keymap_mgr = ui_model.get_keymap_manager()

    scancode_rows = _get_scancode_rows()

    # Scancodes
    scancode_locs = {}
    for row, codes in enumerate(scancode_rows):
        for index, code in enumerate(codes):
            scancode_locs[code] = (row, index)
    keymap_mgr.set_scancode_locations(scancode_locs)

    if _has_xlib:
        display = Xlib.display.Display()

        key_names = {}
        for row, codes in enumerate(scancode_rows):
            for index, code in enumerate(codes):
                keysym = display.keycode_to_keysym(code, 0)
                if keysym != Xlib.X.NoSymbol:
                    name = display.lookup_string(keysym)
                    if name:
                        key_names[(row, index)] = name.upper()

        display.close()

        keymap_mgr.set_key_names(key_names)

    # TODO: set key ID locations for systems that need them

    # Actions
    key_actions = {
        (0, 0):     KeyboardAction(KeyboardAction.REST),
        (2, 9):     KeyboardAction(KeyboardAction.OCTAVE_DOWN),
        (2, 10):    KeyboardAction(KeyboardAction.OCTAVE_UP),
        (3, 7):     KeyboardAction(KeyboardAction.PLAY),
        (3, 8):     KeyboardAction(KeyboardAction.SILENCE),
    }
    tw_sizes = keymap_mgr.get_typewriter_row_sizes()
    tw_offsets = keymap_mgr.get_typewriter_row_offsets()
    for row, (size, offset) in enumerate(zip(tw_sizes, tw_offsets)):
        for index in range(size):
            loc = (row, index + offset)
            assert loc not in key_actions
            key_actions[loc] = KeyboardNoteAction(row, index)
    keymap_mgr.set_key_actions(key_actions)
Пример #7
0
def main():
    display = Xlib.display.Display()
    root = display.screen().root
    root.change_attributes(event_mask = X.KeyReleaseMask)
    screen = wnck.screen_get_default()
    screen.force_update()
    (root_width, root_height) = (screen.get_width(),
                                 screen.get_height() - PANEL_HEIGHT)

    for keysym in KEYMAP:
        if keysym == XK.XK_Num_Lock:
            modifier_mask = 0
        elif keysym < XK.XK_KP_1:
            modifier_mask = KEY_MODIFIER_MASK
        else:
            modifier_mask = PAD_MODIFIER_MASK
        root.grab_key(display.keysym_to_keycode(keysym), modifier_mask, True,
                      X.GrabModeAsync, X.GrabModeAsync)

    check_num_lock()
    while True:
        event = root.display.next_event()
        run_idle()
        if event.type == X.KeyRelease:
            run_idle()
            (root_width, root_height) = (screen.get_width(),
                                         screen.get_height() - PANEL_HEIGHT)
            w = screen.get_active_window()
            for i in range(4):
                try:
                    func = KEYMAP[display.keycode_to_keysym(event.detail, i)]
                    break
                except KeyError:
                    continue
            else:
                raise
            x, y, width, height = w.get_geometry()
            y -= PANEL_HEIGHT
            g = func(w, (root_width, root_height), (x, y, width, height))
            if g is not None:
                print w.get_name(), (x, y, width, height), g
                w.set_geometry(0, 15, g[0], g[1], g[2], g[3])
            run_idle()
Пример #8
0
    def _keycode_to_keysym(self, display, keycode, index):
        """Converts a keycode and shift state index to a keysym.

        This method uses a simplified version of the *X* convention to locate
        the correct keysym in the display table: since this method is only used
        to locate special keys, alphanumeric keys are not treated specially.

        :param display: The current *X* display.

        :param keycode: The keycode.

        :param index: The shift state index.

        :return: a keysym
        """
        keysym = display.keycode_to_keysym(keycode, index)
        if keysym:
            return keysym
        elif index & 0x2:
            return self._keycode_to_keysym(display, keycode, index & ~0x2)
        elif index & 0x1:
            return self._keycode_to_keysym(display, keycode, index & ~0x1)
        else:
            return 0
Пример #9
0
    def _keycode_to_keysym(self, display, keycode, index):
        """Converts a keycode and shift state index to a keysym.

        This method uses a simplified version of the *X* convention to locate
        the correct keysym in the display table: since this method is only used
        to locate special keys, alphanumeric keys are not treated specially.

        :param display: The current *X* display.

        :param keycode: The keycode.

        :param index: The shift state index.

        :return: a keysym
        """
        keysym = display.keycode_to_keysym(keycode, index)
        if keysym:
            return keysym
        elif index & 0x2:
            return self._keycode_to_keysym(display, keycode, index & ~0x2)
        elif index & 0x1:
             return self._keycode_to_keysym(display, keycode, index & ~0x1)
        else:
            return 0
Пример #10
0
def main():
    import sys
    FORMAT = '%(asctime)-15s: %(message)s'
    level = logging.INFO
    if '-v' in sys.argv:
        level = logging.DEBUG
    logging.basicConfig(format=FORMAT, level=level)

    display = Xlib.display.Display()
    root = display.screen().root
    root.change_attributes(event_mask = X.KeyReleaseMask)

    wscreen = wnck.screen_get_default()
    wscreen.force_update()

    gscreen = gtk.gdk.screen_get_default()
    name_to_plists = setup_plist_map(gscreen)

    keysym_to_plists = {}
    for keystr, put_type in OPTS.keymap.iteritems():
        keysym, keymask = keystr_to_sym_mask(keystr)
        if not keysym:
            continue
        logging.debug('%r (keysym %r, keymask %r) => %s', keystr, keysym,
                      keymask, put_type)
        keysym_to_plists[keysym] = name_to_plists[put_type]
        root.grab_key(display.keysym_to_keycode(keysym), keymask, True,
                      X.GrabModeAsync, X.GrabModeAsync)

    check_num_lock()
    while True:
        event = root.display.next_event()
        run_idle()
        if event.type != X.KeyRelease:
            continue

        run_idle()
        for i in range(4):
            try:
                keysym = display.keycode_to_keysym(event.detail, i)
                plists = keysym_to_plists[keysym]
                break
            except KeyError:
                continue
        else:
            logging.warning('got unhandled event %r', event)
            continue

        gw = gscreen.get_active_window()
        if gw is None:
            continue
        mon_idx = gscreen.get_monitor_at_window(gw)
        plist = plists[mon_idx]
        wextents = gw.get_frame_extents()
        p = get_next_placement(plist, wextents)

        ww = wscreen.get_active_window()
        logging.debug('%r (%d, %d, %d, %d) -> (%d, %d, %d, %d)',
                      ww.get_name(), wextents.x, wextents.y, wextents.width,
                      wextents.height, p.x, p.y, p.w, p.h)
        if ww is None:
            continue

        if not p.maximize:
            ww.unmaximize()
        # ww.set_geometry(0, 15, p.x, p.y, p.w, p.h)
        # workaround for set_geometry() not incorporating window decorations.
        dg = ww.get_client_window_geometry()
        ww.set_geometry(0, 15, p.x + (wextents.x - dg[0]),
                        p.y + (wextents.y - dg[1]), p.w, p.h)
        if p.maximize:
            ww.maximize()
        run_idle()