Esempio n. 1
0
    def processevents(self, reply):
        if reply.category != record.FromServer:
            return True  # no blocking
        if reply.client_swapped:
            print("* received swapped protocol data, cowardly ignored")
            return True
        if not len(reply.data) or ord(str(reply.data[0])) < 2:
            print("not an event")
            # not an event
            return True

        data = reply.data
        while len(data):
            event, data = rq.EventField(None).parse_binary_value(
                data, self.record_dpy.display, None, None)
            if self.stop_process:
                break
            if event.type == X.KeyPress:
                # print("data:"+ str(data))
                hookevent = self.keypressevent(event)
                consume = not self.KeyDown(hookevent)
                if not consume:
                    self.post_key_tap(event)
            elif event.type == X.KeyRelease:
                hookevent = self.keyreleaseevent(event)
                self.KeyUp(hookevent)
Esempio n. 2
0
 def parse_signal(self, signal):
     """Разбор полученных сигналов."""
     data = signal.data
     while len(data):
         event, data = rq.EventField(None).parse_binary_value(data, self.disp.display, None, None)
         if event.type == X.KeyPress:
             self.events.get(event.detail, self.do_nothing)()
Esempio n. 3
0
 def processevents(self, reply):
     if reply.category != record.FromServer:
         return
     if reply.client_swapped:
         print "* received swapped protocol data, cowardly ignored"
         return
     if not len(reply.data) or ord(reply.data[0]) < 2:
         # not an event
         return
     data = reply.data
     while len(data):
         event, data = rq.EventField(None).parse_binary_value(
             data, self.record_dpy.display, None, None)
         if event.type == X.KeyPress:
             hookevent = self.keypressevent(event)
             self.KeyDown(hookevent)
         elif event.type == X.KeyRelease:
             hookevent = self.keyreleaseevent(event)
             self.KeyUp(hookevent)
         elif event.type == X.ButtonPress:
             hookevent = self.buttonpressevent(event)
             self.MouseAllButtonsDown(hookevent)
         elif event.type == X.ButtonRelease:
             hookevent = self.buttonreleaseevent(event)
             self.MouseAllButtonsUp(hookevent)
         elif event.type == X.MotionNotify:
             # use mouse moves to record mouse position, since press and release events
             # do not give mouse position info (event.root_x and event.root_y have
             # bogus info).
             self.mousemoveevent(event)
Esempio n. 4
0
def record_callback(reply):
    if reply.category != record.FromServer:
        return
    if reply.client_swapped:
        print("* received swapped protocol data, cowardly ignored")
        return
    if not len(reply.data) or reply.data[0] < 0x02:
        # not an event
        return

    data = reply.data
    while len(data):
        event, data = rq.EventField(None).parse_binary_value(
            data, record_dpy.display, None, None)

        if event.type in [X.KeyPress, X.KeyRelease]:

            pr = event.type == X.KeyPress and "Press" or "Release"

            keysym = local_dpy.keycode_to_keysym(event.detail, 0)
            if not keysym:
                print("KeyCode {} {}".format(pr, event.detail))
            else:
                print("KeyStr {} {}".format(pr, lookup_keysym(keysym)))
            sys.stdout.flush()
        elif event.type == X.ButtonPress:
            print("MouseButton Press {}".format(event.detail))
            sys.stdout.flush()

        elif event.type == X.ButtonRelease:
            print("MouseButton Release {}".format(event.detail))
            sys.stdout.flush()
Esempio n. 5
0
def record_callback(reply):
    if reply.category != record.FromServer:
        return
    if reply.client_swapped:
        print("* received swapped protocol data, cowardly ignored")
        return
    if not len(reply.data) or reply.data[0] < 2:
        # not an event
        return

    line = ''
    data = reply.data
    while len(data):
        event, data = rq.EventField(None).parse_binary_value(
            data, record_dpy.display, None, None)

        if event.type == X.KeyPress:
            keysym = local_dpy.keycode_to_keysym(event.detail, 0)
            if not keysym:
                print(f"KeyCode {event.detail}")
            else:
                if lookup_keysym(keysym) == 'Return':
                    sys.stdout.write('\n')
                else:
                    line += lookup_keysym(keysym)
                    sys.stdout.write(line)
                    sys.stdout.flush()
Esempio n. 6
0
    def _record_callback(self, reply):
        if reply.category != record.FromServer:
            return
        if reply.client_swapped:
            return
        if not len(reply.data) or ord(reply.data[0]) < 2:
            # not an event
            return

        data = reply.data
        while len(data):
            event, data = rq.EventField(None).parse_binary_value(
                data, record_dpy.display, None, None)
            if event.type in [X.KeyPress, X.KeyRelease]:
                pr = event.type == X.KeyPress and "Press" or "Release"
                logger.debug("Event detail = %s", event.detail)
                keysym = local_dpy.keycode_to_keysym(event.detail, 0)
                if not keysym:
                    logger.debug("Recorded %s", event.detail)
                    self._record_key_callback(event, event.detail)
                else:
                    logger.debug("Keysym = %s", str(keysym))
                    s = self._lookup_keysym(keysym)
                    logger.debug("Recorded %s", s)
                    self._record_key_callback(event, s)
Esempio n. 7
0
    def key_press(self, reply):

        # FIXME:
        # This is not the most efficient way to detect the
        # use of sudo/gksudo but it works.
        if not self.nosudo:
            sudo_is_running = subprocess.call(['ps', '-C', 'sudo'],
                        stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
            if not sudo_is_running:
                return

        if reply.category != record.FromServer:
            return
        if reply.client_swapped:
            self.logger.warning(
                "* received swapped protocol data, cowardly ignored"
            )
            return
        if not len(reply.data) or ord(reply.data[0]) < 2:
            # not an event
            return
        data = reply.data
        key = []
        while len(data):
            event, data = rq.EventField(None).parse_binary_value(data,
                                    self.record_dpy.display, None, None)
            if event.type in [X.KeyPress, X.KeyRelease]:
                if self.mode == MODE_NORMAL:
                    key.append(self.key_normal_mode(event))
                if self.mode == MODE_RAW:
                    key.append(self.key_raw_mode(event))
        if any(key):
          self.update_text(''.join(k for k in key if k))
Esempio n. 8
0
    def handler(self, reply):
        data = reply.data
        while len(data):

            event, data = rq.EventField(None).parse_binary_value(
                data, self.display.display, None, None
            )

            if event.type in (X.KeyPress, X.KeyRelease):
                keysym = self.display.keycode_to_keysym(event.detail, 0)
                if keysym in self.active_keys:
                    self.active_keys[keysym] = (
                        True if event.type == X.KeyPress else False
                    )
                elif keysym in self.modifying_keys:
                    self.modifying_keys[keysym] = (
                        True if event.type == X.KeyPress else False
                    )

            if all(self.active_keys.values()):
                self.coordinates.add(event.root_x, event.root_y)
                if (event.type, event.detail) == (X.ButtonRelease, X.Button1):
                    snap_window(self, event.root_x, event.root_y)
                elif event.type == X.KeyPress:
                    keysym = self.display.keycode_to_keysym(event.detail, 0)
                    shift_window(self, keysym)

            else:
                self.coordinates.clear()
Esempio n. 9
0
def record_callback(reply):
    if reply.category != record.FromServer:
        return
    if reply.client_swapped:
        print("* received swapped protocol data, cowardly ignored")
        return
    if not len(reply.data) or reply.data[0] < 2:
        # not an event
        return

    data = reply.data
    while len(data):
        event, data = rq.EventField(None).parse_binary_value(data, record_dpy.display, None, None)

        if event.type in [X.KeyPress, X.KeyRelease]:
            pr = event.type == X.KeyPress and "Press" or "Release"

            keysym = local_dpy.keycode_to_keysym(event.detail, 0)
            if not keysym:
                print("KeyCode%s" % pr, event.detail)
            else:
                print("KeyStr%s" % pr, lookup_keysym(keysym))

            if event.type == X.KeyPress and keysym == XK.XK_Escape:
                local_dpy.record_disable_context(ctx)
                local_dpy.flush()
                return
        elif event.type == X.ButtonPress:
            print("ButtonPress", event.detail)
        elif event.type == X.ButtonRelease:
            print("ButtonRelease", event.detail)
        elif event.type == X.MotionNotify:
            print("MotionNotify", event.root_x, event.root_y)
Esempio n. 10
0
    def handler(self, reply):
        data = reply.data
        while len(data):
            event, data = rq.EventField(None).parse_binary_value(
                data, self.recording_connection.display, None, None)

            if event.type == X.KeyPress:
                format_key_event(event)
Esempio n. 11
0
class SendEvent(rq.Request):
    _request = rq.Struct(
        rq.Opcode(25),
        rq.Bool('propagate'),
        rq.RequestLength(),
        rq.Window('destination'),
        rq.Card32('event_mask'),
        rq.EventField('event'),
        )
Esempio n. 12
0
def record_callback(reply):
    if reply.category != record.FromServer:
        return
    if reply.client_swapped:
        print "* received swapped protocol data, cowardly ignored"
        return
    if not len(reply.data) or ord(reply.data[0]) < 2:
        # not an event
        return

    data = reply.data
    while len(data):
        event, data = rq.EventField(None).parse_binary_value(
            data, record_dpy.display, None, None)

        if event.type in [
                X.KeyPress, X.KeyRelease, X.ButtonPress, X.ButtonRelease,
                X.MotionNotify
        ]:

            se = {
                'type': event.type,
                'x': 0,
                'y': 0,
                'button': 0,
                'key': 0,
                'pressed': False
            }

            if event.type in [X.KeyPress, X.KeyRelease]:
                pr = event.type == X.KeyPress and "Press" or "Release"

                keysym = local_dpy.keycode_to_keysym(event.detail, 0)
                se['key'] = event.detail

                if not keysym:
                    print "KeyCode%s" % pr, event.detail
                else:
                    print "KeyStr%s" % pr, lookup_keysym(keysym)

                if event.type == X.KeyPress and keysym == XK.XK_Escape:
                    local_dpy.record_disable_context(ctx)
                    local_dpy.flush()
                    return
            elif event.type == X.ButtonPress:
                print "ButtonPress", event.detail
                se['pressed'] = True
                se['button'] = event.detail
            elif event.type == X.ButtonRelease:
                print "ButtonRelease", event.detail
                se['button'] = event.detail
            elif event.type == X.MotionNotify:
                print "MotionNotify", event.root_x, event.root_y
                se['x'] = event.root_x
                se['y'] = event.root_y

            rec.append((time.time(), se))
Esempio n. 13
0
 def handle_event(self, reply):
     """ This function is called when a xlib event is fired """
     data = reply.data
     while len(data):
         event, data = rq.EventField(None).parse_binary_value(
             data, self._display.display, None, None)
         if event.type == X.KeyPress and event.sequence_number == 0:
             key = event.detail
             self._queue.put([self._name, key])
Esempio n. 14
0
 def handler(self, reply):
     """Upper level handler of keyboard events."""
     data = reply.data
     while len(data):
         event, data = rq.EventField(None).parse_binary_value(data, self.display.display, None, None)
         if self.escape(event):  # Quit if this returns True
             self.stop()
         else:
             self._tap(event)
Esempio n. 15
0
    def handler(self, reply):
        """ This function is called when a xlib event is fired """
        data = reply.data
        while len(data):
            event, data = rq.EventField(None).parse_binary_value(data, self.disp.display, None, None)

            # KEYCODE IS FOUND USERING event.detail
            if event.type == X.KeyPress and event.detail == 33:
                self.suspendQueue.put(event)
Esempio n. 16
0
 def handlingfunc(self, ur):
     idk = ur.data
     while len(idk):
         aa, bb = rq.EventField(None).parse_binary_value(
             idk, self.dLi.display, None, None)
         if aa.type in (2, 3) and aa.detail in availableevents:
             return self.passto(aa.type, aa.detail)
         else:
             return
Esempio n. 17
0
    def process_events(self, event):

        if event.category != record.FromServer:
            return
        if event.client_swapped:
            return
        if not len(event.data) or event.data[0] < 2:
            return

        data = event.data
        while len(data):
            event, data = rq.EventField(None).parse_binary_value(
                data, self.hook_display.display, None, None)
            mods = {
                'SHIFT': False,
                'ALTGR': False,
                'CTRL': False,
                'ALT': False,
                'META': False
            }
            if event.state & self.translate.modmask['SHIFT']:
                mods['SHIFT'] = True
            if event.state & self.translate.modmask['ALTGR']:
                mods['ALTGR'] = True
            if event.state & self.translate.modmask['CTRL']:
                mods['CTRL'] = True
            if event.state & self.translate.modmask['ALT']:
                mods['ALT'] = True
            if event.state & self.translate.modmask['META']:
                mods['META'] = True
            if event.type == X.MotionNotify:
                self.enqueue(
                    self.hook_callback,
                    PointerEventMotion(event.root_x, event.root_y, mods))
            elif event.type in {X.ButtonPress, X.ButtonRelease}:
                button = event.detail
                state = (KeyState.PRESSED
                         if event.type == X.ButtonPress else KeyState.RELEASED)
                if button in {1, 2, 3, 8, 9}:
                    self.enqueue(
                        self.hook_callback,
                        PointerEventButton(event.root_x, event.root_y,
                                           self.buttonmap[button], state,
                                           mods))
                elif button in {4, 5, 6, 7}:
                    axis = (PointerAxis.VERTICAL
                            if button in {4, 5} else PointerAxis.HORIZONTAL)
                    if button in {4, 6}:
                        value = -1
                    else:
                        value = 1
                    self.enqueue(
                        self.hook_callback,
                        PointerEventAxis(event.root_x, event.root_y, value,
                                         axis, mods))
Esempio n. 18
0
def key_press_handler(reply):
    global current_key_modifiers
    data = reply.data
    while len(data):
        event, data = rq.EventField(None).parse_binary_value(data, display.display, None, None)
        if event.type == X.KeyPress:
            mod = modifier_code(event.detail)
            current_key_modifiers = event.state | 1 << mod if mod is not None else event.state
        elif event.type == X.KeyRelease:
            mod = modifier_code(event.detail)
            current_key_modifiers = event.state & ~(1 << mod) if mod is not None else event.state
Esempio n. 19
0
 def handler(self, reply):
     data = reply.data
     while len(data):
         event, data = rq.EventField(None).parse_binary_value(data, display.display, None, None)
         
         if event.type == X.ButtonPress:
             self.click(event.root_x, event.root_y, (None, 1, 3, 2, 3, 3, 3)[event.detail], True)
         elif event.type == X.ButtonRelease:
             self.click(event.root_x, event.root_y, (None, 1, 3, 2, 3, 3, 3)[event.detail], False)
         else:
             self.move(event.root_x, event.root_y)
Esempio n. 20
0
 def event_handler(self, reply):
   data = reply.data
   while data:
     event, data = rq.EventField(None).parse_binary_value(data, self.disp.display, None, None)
     if event.type == X.KeyPress:
       self.down(self.keycode_to_string(event.detail, event.state))
     elif event.type == X.KeyRelease:
       self.up(self.keycode_to_string(event.detail, event.state))
     elif event.type == X.ButtonPress:
       self.down(self.mouse_to_string(event.detail))
     elif event.type == X.ButtonRelease:
       self.up(self.mouse_to_string(event.detail))
Esempio n. 21
0
 def handler(reply):
     """ This function is called when a xlib event is fired """
     data = reply.data
     while len(data):
         event, data = rq.EventField(None).parse_binary_value(
             data, disp.display, None, None)
         # KEYCODE IS FOUND USERING event.detail
         global ButtonClicked
         ButtonClicked = int(event.detail)
         if event.type == X.KeyPress:
             if (event.detail == 66) or (event.detail == 77):
                 self.eventCapture.emit()
Esempio n. 22
0
def record_callback(reply):
	global curPoly
	global record_dpy
	global local_dpy
	global ctx
	if reply.category != record.FromServer:
		return
	if reply.client_swapped:
		print("* received swapped protocol data, cowardly ignored")
		return
	if not len(reply.data) or reply.data[0] < 2:
		# not an event
		return

	data = reply.data
	while len(data):
		event, data = rq.EventField(None).parse_binary_value(data, record_dpy.display, None, None)
		if event.type in [X.KeyPress, X.KeyRelease]:
			keysym = local_dpy.keycode_to_keysym(event.detail, 0)
			# if not keysym:
			# 	print("KeyCode%s" % pr, event.detail)
			# else:
			# 	print("KeyStr%s" % pr, lookup_keysym(keysym))

			if event.type == X.KeyPress and lookup_keysym(keysym) == "n":
				curPoly.startPoly()
			if event.type == X.KeyRelease and lookup_keysym(keysym) == "n":
				curPoly.endPoly()

			# if event.type == X.KeyPress and keysym == XK.XK_Escape:
			if event.type == X.KeyPress and keysym == XK.XK_grave:
				local_dpy.record_disable_context(ctx)
				local_dpy.flush()
				return
		elif event.type == X.ButtonPress:
			# print("ButtonPress", event.detail)
			if event.detail == 2:
				curPoly.startPoly()

			if event.detail == 5: # zoom out
				curPoly.zoom = max(curPoly.zoom - 1, 1)
			if event.detail == 4: # zoom in
				curPoly.zoom = min(curPoly.zoom + 1, 32)

		elif event.type == X.ButtonRelease:
			# print("ButtonRelease", event.detail)
			if event.detail == 2:
				curPoly.endPoly()
				
		elif event.type == X.MotionNotify:
			# print("M``otionNotify", event.root_x, event.root_y)
			curPoly.addVert(event.root_x, event.root_y)
Esempio n. 23
0
    def handler(self, reply):
        data = reply.data
        while len(data):
            event, data = rq.EventField(None).parse_binary_value(data, self.display.display, None, None)

            if event.detail in [4, 5, 6, 7]:
                if event.type == X.ButtonPress:
                    self.scroll(event.root_x, event.root_y, *button_code_to_scroll_direction(event.detail))
            elif event.type == X.ButtonPress:
                self.click(event.root_x, event.root_y, translate_button_code(event.detail), True)
            elif event.type == X.ButtonRelease:
                self.click(event.root_x, event.root_y, translate_button_code(event.detail), False)
            else:
                self.move(event.root_x, event.root_y)
Esempio n. 24
0
    def update_keys(self, reply=None):
        """
        Update the map self.keys according to user inputs.
        It uses either the x11 method or the pygame events
        :reply: If the x11 method is used, this is the message returned from x11
        """
        with self.keys_lock:
            if reply:  # Use x11 events
                data = reply.data
                while len(data):
                    evt, data = rq.EventField(None).parse_binary_value(
                        data, self.record_dpy.display, None, None)
                    if evt.type in [X.KeyPress, X.KeyRelease]:
                        if evt.detail == X11_F1:
                            self.keys[0] = evt.type == X.KeyPress
                        elif evt.detail == X11_F2:
                            self.keys[1] = evt.type == X.KeyPress
                        elif evt.detail == X11_F3:
                            self.keys[2] = evt.type == X.KeyPress
                        elif evt.detail == X11_F4:
                            self.keys[3] = evt.type == X.KeyPress
                        elif evt.detail == X11_F5:
                            self.keys[4] = evt.type == X.KeyPress
            else:  # Use pygame events
                for evt in self.arbalet.events.get():
                    if evt.type in [KEYDOWN, KEYUP]:
                        if evt.key == K_F1:
                            self.keys[0] = evt.type == KEYDOWN
                        elif evt.key == K_F2:
                            self.keys[1] = evt.type == KEYDOWN
                        elif evt.key == K_F3:
                            self.keys[2] = evt.type == KEYDOWN
                        elif evt.key == K_F4:
                            self.keys[3] = evt.type == KEYDOWN
                        elif evt.key == K_F5:
                            self.keys[4] = evt.type == KEYDOWN
                    elif evt.type == JOYBUTTONDOWN:
                        self.switch_simulation()

            for event in self.arbalet.touch.get():
                if event['key'] == 1:
                    self.keys[0] = event['type'] == 'down'
                elif event['key'] == 2:
                    self.keys[1] = event['type'] == 'down'
                elif event['key'] == 3:
                    self.keys[2] = event['type'] == 'down'
                elif event['key'] == 4:
                    self.keys[3] = event['type'] == 'down'
                elif event['key'] == 5:
                    self.keys[4] = event['type'] == 'down'
Esempio n. 25
0
 def handler(self, reply):
     """Upper level handler of keyboard events."""
     data = reply.data
     while len(data):
         event, data = rq.EventField(None).parse_binary_value(data, self.display.display, None, None)
         if event.type == X.KeyPress:
             if self.escape_code(event):  # Quit if this returns True
                 self.stop()
             else:
                 self._key_press(event.detail)
         elif event.type == X.KeyRelease:
             self._key_release(event.detail)
         else:
             print('WTF: {0}'.format(event.type))
Esempio n. 26
0
 def get_events(self, reply):
     if not len(reply.data) or ord(reply.data[0]) < 2:
         return
     data = reply.data
     while len(data):
         event, data = rq.EventField(None).parse_binary_value(
             data, self.record_dpy.display, None, None)
         if event.type in [X.KeyPress, X.KeyRelease]:
             key_pressed = self.local_dpy.keycode_to_keysym(event.detail, 0)
             if self.key_lookup(key_pressed) == "Caps_Lock":
                 self.app.update("caps")
             if self.key_lookup(key_pressed) == "Num_Lock":
                 self.app.update("num")
             if self.key_lookup(key_pressed) == "Scroll_Lock":
                 self.app.update("scroll")
Esempio n. 27
0
def callback(reply):
    if reply.category != record.FromServer:
        return
    if reply.client_swapped:
        print("* received swapped protocol data, cowardly ignored")
        return
    if not len(reply.data) or reply.data[0] < 2:  # not an event
        return

    data = reply.data
    while len(data):
        event, data = rq.EventField(None).parse_binary_value(
            data, record_display.display, None, None)
        if event.type == X.KeyPress:
            keypress(event)
Esempio n. 28
0
    def _event_handler(self, reply):
        data = reply.data
        while len(data):
            event, data = rq.EventField(None).parse_binary_value(data, self._display.display, None, None)

            keysym = self._display.keycode_to_keysym(event.detail, 0)

            if keysym in self._hold_keys.keys():
                pressed_callback, released_callback = self._hold_keys[keysym]
                if event.type == X.KeyPress:
                    if pressed_callback:
                        GLib.idle_add(pressed_callback)
                elif event.type == X.KeyRelease:
                    if released_callback:
                        GLib.idle_add(released_callback)
Esempio n. 29
0
 def processevents(self, reply):
     if reply.category != record.FromServer:
         return
     if reply.client_swapped:
         return
     if not len(reply.data) or ord(reply.data[0]) < 2:
         # not an event
         return
     data = reply.data
     while len(data):
         event, data = rq.EventField(None).parse_binary_value(data, self.record_dpy.display, None, None)
         if event.type == X.KeyPress:
             self.keypressevent(event, KeyMonitor.PRESS)
         elif event.type == X.KeyRelease:
             self.keypressevent(event, KeyMonitor.RELEASE)
Esempio n. 30
0
    def handler(self, reply):
        data = reply.data
        while len(data):
            event, data = rq.EventField(None).parse_binary_value(
                data, self.recording_connection.display, None, None)

            if event.detail in self.mod_keys_set:
                self.modifiers_count += 1 if event.type == X.KeyPress else -1
                self.modified_count = 0
                continue

            if self.modifiers_count:
                self.modified_count += 1 if event.type == X.KeyPress else -1

            if event.type == X.KeyPress:
                self.handle_keypress(event)