Ejemplo n.º 1
0
def process_key_event(id_no, keyval, modmask, backslash, pressed = None):
    def update_keymap():
        display._update_keymap(display.display.info.min_keycode,
                               (display.display.info.max_keycode
                                - display.display.info.min_keycode + 1))

    def reply(id_no, handled):
        # editing = len()
        # imcontexts[id_no].editing  how do i know current input status 
        print_command('ibus_process_key_event_cb', id_no, handled)
        return False

    ic = imcontexts[id_no]
    if use_surrounding_text and pressed != False \
            and ic.needs_surrounding_text() and not ic.surrouding_text_received:
        print_command('ibus_query_surrounding_text_cb',
            id_no, keyval, modmask, backslash, pressed)
        return

    if backslash:
        keycode = display.keysym_to_keycode(backslash) - 8
        if keycode < 0:
            update_keymap()
            keycode = display.keysym_to_keycode(backslash) - 8
    else:
        keycodes = display.keysym_to_keycodes(keyval)
        if not keycodes:
            update_keymap()
            keycodes = display.keysym_to_keycodes(keyval) or [(0, 0)]
        if modmask & modifier.SHIFT_MASK:
            for keycode_tuple in keycodes:
                if keycode_tuple[1] & 1:
                    break
            else:
                keycode_tuple = keycodes[0]
        elif keyval < 0x100:
            for keycode_tuple in keycodes:
                if keycode_tuple[1]:
                    if keycode_tuple[1] > 1:
                        keycode_tuple = keycodes[0]
                    break
            else:
                keycode_tuple = keycodes[0]
            if keycode_tuple[1] & 1:
                modmask |= modifier.SHIFT_MASK
        else:
            keycode_tuple = keycodes[0]
        keycode = keycode_tuple[0] - 8
    if pressed != None:
        if not pressed:
            modmask |= modifier.RELEASE_MASK
        handled = ic.process_key_event(keyval, keycode, modmask)
    else:
        handled_p = ic.process_key_event(keyval, keycode, modmask)
        handled_r = ic.process_key_event(keyval, keycode,
                                         modmask | modifier.RELEASE_MASK)
        handled = handled_p or handled_r
    glib.idle_add(reply, id_no, handled)
Ejemplo n.º 2
0
def process_key_event(id_no, keyval, modmask, backslash, pressed=None):
    def update_keymap():
        display._update_keymap(display.display.info.min_keycode,
                               (display.display.info.max_keycode -
                                display.display.info.min_keycode + 1))

    def reply(id_no, handled):
        print_command('ibus_process_key_event_cb', id_no, handled)
        return False

    ic = imcontexts[id_no]
    if use_surrounding_text and pressed != False \
            and ic.needs_surrounding_text() and not ic.surrouding_text_received:
        print_command('ibus_query_surrounding_text_cb', id_no, keyval, modmask,
                      backslash, pressed)
        return

    if backslash:
        keycode = display.keysym_to_keycode(backslash) - 8
        if keycode < 0:
            update_keymap()
            keycode = display.keysym_to_keycode(backslash) - 8
    else:
        keycodes = display.keysym_to_keycodes(keyval)
        if not keycodes:
            update_keymap()
            keycodes = display.keysym_to_keycodes(keyval) or [(0, 0)]
        if modmask & modifier.SHIFT_MASK:
            for keycode_tuple in keycodes:
                if keycode_tuple[1] & 1:
                    break
            else:
                keycode_tuple = keycodes[0]
        elif keyval < 0x100:
            for keycode_tuple in keycodes:
                if keycode_tuple[1]:
                    if keycode_tuple[1] > 1:
                        keycode_tuple = keycodes[0]
                    break
            else:
                keycode_tuple = keycodes[0]
            if keycode_tuple[1] & 1:
                modmask |= modifier.SHIFT_MASK
        else:
            keycode_tuple = keycodes[0]
        keycode = keycode_tuple[0] - 8
    if pressed != None:
        if not pressed:
            modmask |= modifier.RELEASE_MASK
        handled = ic.process_key_event(keyval, keycode, modmask)
    else:
        handled_p = ic.process_key_event(keyval, keycode, modmask)
        handled_r = ic.process_key_event(keyval, keycode,
                                         modmask | modifier.RELEASE_MASK)
        handled = handled_p or handled_r
    glib.idle_add(reply, id_no, handled)
Ejemplo n.º 3
0
 def send_key(display, window, keycodes):
     '''Send a KeyPress and KeyRelease event'''
     if not type(keycodes) in (tuple, list):
         keycodes = (keycodes, )
     # send with modifier
     for keycode in keycodes:
         xtest.fake_input(window, X.KeyPress,
                          display.keysym_to_keycode(keycode))
     for keycode in reversed(keycodes):
         xtest.fake_input(window, X.KeyRelease,
                          display.keysym_to_keycode(keycode))
     display.sync()
Ejemplo n.º 4
0
 def send_key(display, window, keycodes):
     '''Send a KeyPress and KeyRelease event'''
     if not type(keycodes) in (tuple, list):
         keycodes = (keycodes,)
     # send with modifier
     for keycode in keycodes:
         xtest.fake_input(window,
                          X.KeyPress,
                          display.keysym_to_keycode(keycode))
     for keycode in reversed(keycodes):
         xtest.fake_input(window,
                          X.KeyRelease,
                          display.keysym_to_keycode(keycode))
     display.sync()
Ejemplo n.º 5
0
def remap_keys(remap):
  """ Remap keycode -> keysym for function keys

  The keycode -> keysym mapping is so that the keycode generated
  when the F1 key is pressed sends the F25 keysym. But to do that you
  need to know the keycodes for F1-10, for Linux on x86 the keycode for
  F1 is 67 but for other platforms it could be different. So the code
  looks up the keycode mapped to F1 keysym if that is non zero (i.e. F1
  is mapped) I map that keycode to F1 or F25 as required, if F1 is not
  mapped I lookup the keycode for F25 and if that is non zero I map
  that keycode to F1 or F25 as required. If F1 and F25 are not mapped
  to any keycode I use 67 as the keycode for the F1 key. The code
  assumes that the keycodes for F1-10 are sequential which may not be
  true for all platforms. A more robust solution may be found by
  accessing the keyboard layout somehow but I haven't had time to look
  yet.
  """
  
  display = Xlib.display.Display()
  
  # only keycodes 8 to 255 are defined
  first_keycode = 8
  keymaps_orig = display.get_keyboard_mapping(first_keycode, 255 - first_keycode)
  keymaps = list(keymaps_orig)

  if remap == True: 
    keysym = 65494
  else:
    keysym = 65470

  keycode_F1 = display.keysym_to_keycode(65470)
  keycode_F25 = display.keysym_to_keycode(65494)
  
  # set first_fkeycode to a sensible default incase F1 and F25 are not mapped
  first_fkeycode = 67
  
  if keycode_F1 > 0:
    first_fkeycode = keycode_F1
  elif keycode_F25 > 0:
    first_fkeycode = keycode_F25
    
  for i in range(0, 10):

    keymaps[(i + first_fkeycode - first_keycode)][0] = keysym + i
    keymaps[(i + first_fkeycode - first_keycode)][2] = keysym + i
    keymaps[(i + first_fkeycode - first_keycode)][4] = keysym + i
    
  display.change_keyboard_mapping(first_keycode, keymaps, onerror = None)
  display.sync()
  display.close()
Ejemplo n.º 6
0
def remap_keys(remap):
   """ Remap keycode -> keysym for function keys
   
   The keycode -> keysym mapping is so that the keycode generated
   when the F1 key is pressed sends the F25 keysym. But to do that you
   need to know the keycodes for F1-10, for Linux on x86 the keycode for
   F1 is 67 but for other platforms it could be different. So the code
   looks up the keycode mapped to F1 keysym if that is non zero (i.e. F1
   is mapped) I map that keycode to F1 or F25 as required, if F1 is not
   mapped I lookup the keycode for F25 and if that is non zero I map
   that keycode to F1 or F25 as required. If F1 and F25 are not mapped
   to any keycode I use 67 as the keycode for the F1 key. The code
   assumes that the keycodes for F1-10 are sequential which may not be
   true for all platforms. A more robust solution may be found by
   accessing the keyboard layout somehow but I haven't had time to look
   yet.
   """
   
   display = Xlib.display.Display()
  
   # only keycodes 8 to 255 are defined
   first_keycode = 8
   keymaps_orig = display.get_keyboard_mapping(first_keycode, 255 - first_keycode)
   keymaps = list(keymaps_orig)
   
   if remap == True: 
      keysym = 65494
   else:
      keysym = 65470
   
   keycode_F1 = display.keysym_to_keycode(65470)
   keycode_F25 = display.keysym_to_keycode(65494)
  
   # set first_fkeycode to a sensible default incase F1 and F25 are not mapped
   first_fkeycode = 67
  
   if keycode_F1 > 0:
      first_fkeycode = keycode_F1
   elif keycode_F25 > 0:
      first_fkeycode = keycode_F25
   
   for i in range(0, int(number_of_suggestions)):

      keymaps[(i + first_fkeycode - first_keycode)][0] = keysym + i
      keymaps[(i + first_fkeycode - first_keycode)][2] = keysym + i
      keymaps[(i + first_fkeycode - first_keycode)][4] = keysym + i
   
   display.change_keyboard_mapping(first_keycode, keymaps, onerror = None)
   display.sync()
   display.close()
Ejemplo n.º 7
0
 def right_action():
     keycode = display.keysym_to_keycode(
         Xlib.XK.string_to_keysym('Right')
     )
     Xlib.ext.xtest.fake_input(display, Xlib.X.KeyPress, keycode)
     Xlib.ext.xtest.fake_input(display, Xlib.X.KeyRelease, keycode)
     display.sync()
Ejemplo n.º 8
0
def char_to_keycode(ch):
    keysym = get_keysym(ch)
    keycode = display.keysym_to_keycode(keysym)
    if keycode == 0:
        print "Sorry, can't map", ch

    return keycode
Ejemplo n.º 9
0
def char_to_keycode(ch):
    keysym = get_keysym(ch)
    keycode = display.keysym_to_keycode(keysym)
    if keycode == 0:
        print "Sorry, can't map", ch

    return keycode
Ejemplo n.º 10
0
def char_to_keycode(ch) :
	keysym = get_keysym(ch)
#	print keysym
	keycode = display.keysym_to_keycode(keysym)
#	if keycode == 0 :
#		print "Sorry, can't map", ch
#	print keycode
	return keycode
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
Ejemplo n.º 12
0
def char_to_keycode(ch):
    keysym = get_keysym(ch)
    # 	print keysym
    keycode = display.keysym_to_keycode(keysym)
    # 	if keycode == 0 :
    # 		print "Sorry, can't map", ch
    # 	print keycode
    return keycode
Ejemplo n.º 13
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
Ejemplo n.º 14
0
    def _find_mask(self, display, symbol):
        modifier_keycode = display.keysym_to_keycode(
            Xlib.XK.string_to_keysym(symbol))

        for index, keycodes in enumerate(display.get_modifier_mapping()):
            for keycode in keycodes:
                if keycode == modifier_keycode:
                    return 1 << index

        return 0
Ejemplo n.º 15
0
def char_to_keycode(ch) :
    keysym = get_keysym(ch)
    keycode = display.keysym_to_keycode(keysym)
    if keycode == 0 :
        print "Sorry, can't map", ch

    if (is_shifted(ch)) :
        shift_mask = Xlib.X.ShiftMask
    else :
        shift_mask = 0
    return keycode, shift_mask
Ejemplo n.º 16
0
def char_to_keycode(ch):
    keysym = get_keysym(ch)
    keycode = display.keysym_to_keycode(keysym)
    if keycode == 0:
        print "Sorry, can't map", ch

    if (is_shifted(ch)):
        shift_mask = Xlib.X.ShiftMask
    else:
        shift_mask = 0

    return keycode, shift_mask
Ejemplo n.º 17
0
def sequence2codes(display, sequence):
    '''Convert a string to a series of keycodes to be gobled by CRiSP.'''
    #   start with F16
    codes = [F16]
    for string in sequence:
        #       add "<" to signal start of character
        codes.append(Less)
        for letter in string:
            if letter.isupper():
                # tuple indicates key with modifier pressed
                codes.append((Shift_L, display.keysym_to_keycode(ord(letter))))
            else:
                # int means regular keycode
                codes.append(display.keysym_to_keycode(ord(letter)))
#       add ">" to signal end of character
        codes.append((Shift_L, Less))


#   finish with "Return"
    codes.append(Return)
    return codes
Ejemplo n.º 18
0
def send_key(emulated_key):
	window = display.get_input_focus()._data["focus"];
	
	# Generate the correct keycode
	keysym = Xlib.XK.string_to_keysym(emulated_key)
	keycode = display.keysym_to_keycode(keysym)
	
	# Send a fake keypress via xtest
	Xlib.ext.xtest.fake_input(display, Xlib.X.KeyPress, keycode)
	display.sync()
	time.sleep(0.5)
	Xlib.ext.xtest.fake_input(display, Xlib.X.KeyRelease, keycode)
	display.sync()
Ejemplo n.º 19
0
        def perform_key_event(accelerator, press, delay):
            import Xlib
            from Xlib import X
            from Xlib.display import Display
            from Xlib.ext.xtest import fake_input
            from Xlib.protocol.event import KeyPress, KeyRelease
            import time

            import gi
            gi.require_version('Gtk', '3.0')
            from gi.repository import Gtk, Gdk, GdkX11

            keysym, modifiers = Gtk.accelerator_parse(accelerator)
            display = Display()
            # root = display.screen().root
            # window = root.query_pointer().child
            # window.set_input_focus(X.RevertToParent, X.CurrentTime)
            # window.configure(stack_mode=X.Above)
            # display.sync()

            keycode = display.keysym_to_keycode(keysym)

            if press:
                event_type = X.KeyPress
            else:
                event_type = X.KeyRelease

            if keycode != 0:
                if 'GDK_CONTROL_MASK' in modifiers.value_names:
                    modcode = display.keysym_to_keycode(Gdk.KEY_Control_L)
                    fake_input(display, event_type, modcode, delay)

                if 'GDK_SHIFT_MASK' in modifiers.value_names:
                    modcode = display.keysym_to_keycode(Gdk.KEY_Shift_L)
                    fake_input(display, event_type, modcode, delay)

                fake_input(display, event_type, keycode, delay)
                display.sync()
Ejemplo n.º 20
0
	def grab_keys(keys):
		for (code, mask), func in keys.items():
			code = display.keysym_to_keycode(code)
			if (code, mask) == (0, 0):
				continue
			bound[code, mask] = func
			bound[code, mask | X.Mod2Mask] = func
			bound[code, mask | X.LockMask] = func
			bound[code, mask | X.Mod2Mask | X.LockMask] = func

		root = display.screen().root
		for key in bound.keys():
			root.grab_key(key[0], key[1], 1, X.GrabModeAsync, X.GrabModeAsync)
		display.sync()
Ejemplo n.º 21
0
Archivo: xk.py Proyecto: CorinnaRa/tdr
def release_key(keysym, shift_mask = 0) :
    keycode = display.keysym_to_keycode(keysym)
    if (UseXTest) :
        Xlib.ext.xtest.fake_input(display, Xlib.X.KeyRelease, keycode)
        if shift_mask != 0 :
            Xlib.ext.xtest.fake_input(display, Xlib.X.KeyRelease, 50)
    else :
        event = Xlib.protocol.event.KeyRelease(
            time = int(time.time()),
            root = display.screen().root,
            window = window,
            same_screen = 0, child = Xlib.X.NONE,
            root_x = 0, root_y = 0, event_x = 0, event_y = 0,
            state = shift_mask,
            detail = keycode
            )
        window.send_event(event, propagate = True)
    display.sync()
Ejemplo n.º 22
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()
Ejemplo n.º 23
0
def _find_mask(display, symbol):
    """Returns the mode flags to use for a modifier symbol.

    :param Xlib.display.Display display: The *X* display.

    :param str symbol: The name of the symbol.

    :return: the modifier mask
    """
    # Get the key code for the symbol
    modifier_keycode = display.keysym_to_keycode(
        Xlib.XK.string_to_keysym(symbol))

    for index, keycodes in enumerate(display.get_modifier_mapping()):
        for keycode in keycodes:
            if keycode == modifier_keycode:
                return 1 << index

    return 0
Ejemplo n.º 24
0
def _find_mask(display, symbol):
    """Returns the mode flags to use for a modifier symbol.

    :param Xlib.display.Display display: The *X* display.

    :param str symbol: The name of the symbol.

    :return: the modifier mask
    """
    # Get the key code for the symbol
    modifier_keycode = display.keysym_to_keycode(
        Xlib.XK.string_to_keysym(symbol))

    for index, keycodes in enumerate(display.get_modifier_mapping()):
        for keycode in keycodes:
            if keycode == modifier_keycode:
                return 1 << index

    return 0
Ejemplo n.º 25
0
    actions["Mouse Move Slow Up"] = Action(win32KeyCode = (0,-5),mouseMovement=True)
    actions["Mouse Move Slow Down"] = Action(win32KeyCode = (0,5),mouseMovement=True)
    actions["Mouse Move Fast Left"] = Action(win32KeyCode = (-50,0),mouseMovement=True)
    actions["Mouse Move Fast Right"] = Action(win32KeyCode = (50,0),mouseMovement=True)
    actions["Mouse Move Fast Up"] = Action(win32KeyCode = (0,-50),mouseMovement=True)
    actions["Mouse Move Fast Down"] = Action(win32KeyCode = (0,50),mouseMovement=True)
    actions["Tab"] = Action(win32KeyCode = 0x09,extend=True ) 
    actions["Shift"] = Action(win32KeyCode = 0x10,extend=True )
    actions["Control"] = Action(win32KeyCode = 0x11,extend=True )
    actions["Alt"] = Action(win32KeyCode = 0x12,extend=True )


if haveXlib:
    display = Xlib.display.Display()
    for each in "1234567890abcdefghijklmnopqrstuvwxyz":
        actions[each] = Action(xLibKeyCode= display.keysym_to_keycode(ord(each)))
        #actions[each.upper()] = Action(xLibKeyCode= display.keysym_to_keycode(each),shiftDown=True)
        #actions["Ctrl "+each] = Action(xLibKeyCode= display.keysym_to_keycode(each),controlDown=True)
        #actions["Ctrl "+each.upper()] = Action(xLibKeyCode= display.keysym_to_keycode(each),shiftDown=True,controlDown=True)
        #actions["Alt "+each] = Action(xLibKeyCode= display.keysym_to_keycode(each),altDown=True)
        #actions["Alt "+each.upper()] = Action(xLibKeyCode= display.keysym_to_keycode(each),shiftDown=True,altDown=True)
        #actions["Ctrl Alt "+each] = Action(xLibKeyCode= display.keysym_to_keycode(each),controlDown=True,altDown=True)
        #actions["Ctrl Alt "+each.upper()] = Action(xLibKeyCode= display.keysym_to_keycode(each),shiftDown=True,controlDown=True,altDown=True)
    actions["Arrow Left"] = Action(xLibKeyCode=113)
    actions["Arrow Right"] = Action(xLibKeyCode=114)
    actions["Arrow Up"] = Action(xLibKeyCode=111)
    actions["Arrow Down"] = Action(xLibKeyCode=116)
    actions["F1"] = Action(xLibKeyCode=67)
    actions["F2"] = Action(xLibKeyCode=68)
    actions["F3"] = Action(xLibKeyCode=69)
    actions["F4"] = Action(xLibKeyCode=70)
def getSpecialkeycode(keyname):
    for speciealKey in specialKeys:
        if speciealKey[0] == keyname:
            return display.keysym_to_keycode(speciealKey[1])
    return 0
Ejemplo n.º 27
0
def getSpecialkeycode(keyname):
	for speciealKey in specialKeys :
		if speciealKey[0] == keyname :
			return display.keysym_to_keycode(speciealKey[1])
	return 0
Ejemplo n.º 28
0
    actions["Mouse Move Fast Right"] = Action(win32KeyCode=(50, 0),
                                              mouseMovement=True)
    actions["Mouse Move Fast Up"] = Action(win32KeyCode=(0, -50),
                                           mouseMovement=True)
    actions["Mouse Move Fast Down"] = Action(win32KeyCode=(0, 50),
                                             mouseMovement=True)
    actions["Tab"] = Action(win32KeyCode=0x09, extend=True)
    actions["Shift"] = Action(win32KeyCode=0x10, extend=True)
    actions["Control"] = Action(win32KeyCode=0x11, extend=True)
    actions["Alt"] = Action(win32KeyCode=0x12, extend=True)

if haveXlib:
    display = Xlib.display.Display()
    for each in "1234567890abcdefghijklmnopqrstuvwxyz":
        actions[each] = Action(
            xLibKeyCode=display.keysym_to_keycode(ord(each)))
        #actions[each.upper()] = Action(xLibKeyCode= display.keysym_to_keycode(each),shiftDown=True)
        #actions["Ctrl "+each] = Action(xLibKeyCode= display.keysym_to_keycode(each),controlDown=True)
        #actions["Ctrl "+each.upper()] = Action(xLibKeyCode= display.keysym_to_keycode(each),shiftDown=True,controlDown=True)
        #actions["Alt "+each] = Action(xLibKeyCode= display.keysym_to_keycode(each),altDown=True)
        #actions["Alt "+each.upper()] = Action(xLibKeyCode= display.keysym_to_keycode(each),shiftDown=True,altDown=True)
        #actions["Ctrl Alt "+each] = Action(xLibKeyCode= display.keysym_to_keycode(each),controlDown=True,altDown=True)
        #actions["Ctrl Alt "+each.upper()] = Action(xLibKeyCode= display.keysym_to_keycode(each),shiftDown=True,controlDown=True,altDown=True)
    actions["Arrow Left"] = Action(xLibKeyCode=113)
    actions["Arrow Right"] = Action(xLibKeyCode=114)
    actions["Arrow Up"] = Action(xLibKeyCode=111)
    actions["Arrow Down"] = Action(xLibKeyCode=116)
    actions["F1"] = Action(xLibKeyCode=67)
    actions["F2"] = Action(xLibKeyCode=68)
    actions["F3"] = Action(xLibKeyCode=69)
    actions["F4"] = Action(xLibKeyCode=70)
Ejemplo n.º 29
0
import os
if os.name == 'nt':
	# Windows
	import win32com.client
	shell = win32com.client.Dispatch("WScript.Shell")
elif os.name == 'posix':
	# Linux
	import Xlib.display
	import Xlib.X
	import Xlib.XK
	import Xlib.protocol.event
	import Xlib.ext.xtest

	display = Xlib.display.Display()

	ctrlkey=display.keysym_to_keycode(Xlib.XK.XK_Control_L)
	altkey=display.keysym_to_keycode(Xlib.XK.XK_Alt_L)
	shiftkey=display.keysym_to_keycode(Xlib.XK.XK_Shift_L)

	specialKeys = (
	("BACKSPACE",Xlib.XK.XK_BackSpace),
	("BS",Xlib.XK.XK_BackSpace),
	("BKSP",Xlib.XK.XK_BackSpace),
	("BREAK",Xlib.XK.XK_Break),
	("CAPSLOCK",Xlib.XK.XK_Caps_Lock),
	("DELETE",Xlib.XK.XK_Delete),
	("DEL",Xlib.XK.XK_Delete),
	("DOWN",Xlib.XK.XK_Down),
	("END",Xlib.XK.XK_End),
	("ENTER",Xlib.XK.XK_KP_Enter),
	("ESC",Xlib.XK.XK_Escape),
Ejemplo n.º 30
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()
Ejemplo n.º 31
0
		# Unfortunately, although this works to get the correct keysym
		# i.e. keysym for '#' is returned as "numbersign"
		# the subsequent display.keysym_to_keycode("numbersign") is 0.
		keysym = Xlib.XK.string_to_keysym(special_X_keysyms[ch])
	return keysym

def char_to_keycode(ch) :
	keysym = get_keysym(ch)
#	print keysym
	keycode = display.keysym_to_keycode(keysym)
#	if keycode == 0 :
#		print "Sorry, can't map", ch
#	print keycode
	return keycode

ctrlkey=display.keysym_to_keycode(Xlib.XK.XK_Control_L)
altkey=display.keysym_to_keycode(Xlib.XK.XK_Alt_L)
shiftkey=display.keysym_to_keycode(Xlib.XK.XK_Shift_L)

def sendkey(keystroke):
	ctrl = alt = shift = 0
	key = ""
	splitted = keystroke.split(" ")
	for stroke in splitted:
		if stroke == "Ctrl":
			ctrl = 1
		elif stroke == "Shift":
			shift = 1
		elif stroke == "Alt":
			alt = 1
		elif stroke == "Space": 
Ejemplo n.º 32
0
def keysym_to_keycode(keysym):
    keycode = display.keysym_to_keycode(keysym)
    shift_mask = 0
    return keycode, shift_mask
# Image data, RGBA8 format, bottom-left coordinates
# Note that OpenCV expects BGRA8 and top-left coordinates
image = None

blob_pos = (0.0, 0.0)

mouse_down = 0
cursor_posx = 0.0
cursor_posy = 0.0

# X11 junk
display = Xlib.display.Display()
dest_window = None
charkeys = {
        'w': display.keysym_to_keycode(latin1.XK_w),
        'a': display.keysym_to_keycode(latin1.XK_a),
        's': display.keysym_to_keycode(latin1.XK_s),
        'd': display.keysym_to_keycode(latin1.XK_d),
        'Escape': display.keysym_to_keycode(miscellany.XK_Escape)
        }

old_keys = []

# Blob detector instance
params = cv2.SimpleBlobDetector_Params()
params.blobColor = 255
detector = cv2.SimpleBlobDetector(params)

def render():
    global image
Ejemplo n.º 34
0
Archivo: linux.py Proyecto: pbfy0/pykbm
def _get_keycode(char):
    return display.keysym_to_keycode(_get_keysym(char))
Ejemplo n.º 35
0
def keysym_to_keycode(keysym):
    keycode = display.keysym_to_keycode(keysym)
    shift_mask = 0
    return keycode, shift_mask
Ejemplo n.º 36
0
def send_keysym( keysym, display ):
    key = display.keysym_to_keycode( keysym )
    Xlib.ext.xtest.fake_input(display, Xlib.X.KeyPress, key)
    Xlib.ext.xtest.fake_input(display, Xlib.X.KeyRelease, key)
    display.sync()