예제 #1
0
    def __init__(self, log_event_details=False):
        threading.Thread.__init__(self)
        self.finished = threading.Event()

        self.log_events = log_event_details
        self.log_events_file = None

        # Give these some initial values
        self.mouse_position_x = 0
        self.mouse_position_y = 0

        # Assign default function actions (do nothing).
        self.KeyDown = lambda x: True
        self.KeyUp = lambda x: True
        self.MouseAllButtonsDown = lambda x: True
        self.MouseAllButtonsUp = lambda x: True
        self.MouseAllMotion = lambda x: True
        self.contextEventMask = [X.KeyPress, X.MotionNotify]

        # Used to hold any keys currently pressed and the repeat count
        # of each key.
        self.key_states = dict()

        self.contextEventMask = [X.KeyPress, X.MotionNotify]

        # Hook to our display.
        self.local_dpy = display.Display()
        self.record_dpy = display.Display()

        self.ioHubMouseButtonMapping = {
            1: 'MOUSE_BUTTON_LEFT',
            2: 'MOUSE_BUTTON_MIDDLE',
            3: 'MOUSE_BUTTON_RIGHT'
        }
        self.pressedMouseButtons = 0
        self.scroll_y = 0

        # Direct xlib ctypes wrapping for better / faster keyboard event -> key,
        # char field mapping.
        self._xlib = _xlib
        self._xdisplay = _xlib.XOpenDisplay(None)
        self._xroot = _xlib.XDefaultRootWindow(self._xdisplay)
        self._keysym = _xlib.KeySym()
        self._compose = _xlib.XComposeStatus()
        self._tmp_compose = _xlib.XComposeStatus()
        self._revert = ct.c_int(0)
        self._charbuf = (ct.c_char * 17)()
        self._cwin = _xlib.Window()
        self._revert_to_return = ct.c_int()

        self._xkey_evt = _xlib.XKeyEvent()
        self._xkey_evt.serial = 1  # not known, make it up.
        self._xkey_evt.send_event = 0
        self._xkey_evt.subwindow = 0
        self._xkey_evt.display = self._xdisplay
        self._xkey_evt.root = self._xroot  #', Window),
        self._xkey_evt.subwindow = 0  #', Window)
예제 #2
0
 def _event_keypress(self, kev, data):
     buf = xlib.create_string_buffer(16)
     keysym = xlib.KeySym()
     status = xlib.Status()
     ret = xlib.Xutf8LookupString(self._kbd_replay_xic, kev, buf, len(buf),
                                  xlib.byref(keysym), xlib.byref(status))
     if ret != xlib.NoSymbol:
         if 32 <= keysym.value <= 126:
             # avoid ctrl sequences, just take the character value
             data.string = chr(keysym.value)
         else:
             try:
                 data.string = buf.value.decode('utf-8')
             except UnicodeDecodeError:
                 pass
     data.keysym = keysym.value
     data.status = status.value