def invalidate(self): ''' Cause the window to be redraw on the main window ''' # Dummy event for performing update in the main thread # TODO do this better e = Xlib.protocol.event.KeyPress(detail = 1, time = Xlib.X.CurrentTime, root = display.screen().root, window = self.window, child = Xlib.X.NONE, root_x = 1, root_y = 1, event_x = 1, event_y = 1, state = 0, same_screen = 1) display.send_event(self.window, e) display.flush()
def invalidate(self): ''' Cause the window to be redraw on the main window ''' # Dummy event for performing update in the main thread # TODO do this better e = Xlib.protocol.event.KeyPress(detail=1, time=Xlib.X.CurrentTime, root=display.screen().root, window=self.window, child=Xlib.X.NONE, root_x=1, root_y=1, event_x=1, event_y=1, state=0, same_screen=1) display.send_event(self.window, e) display.flush()
def do_input(): global old_keys new_keys = [] # Map cursor position to key presses if blob_pos is not None: if blob_pos[0] > 2.0 / 3.0 * WINDOW_WIDTH: new_keys.append('d') elif blob_pos[0] < 1.0 / 3.0 * WINDOW_WIDTH: new_keys.append('a') if blob_pos[1] > 2.0 / 3.0 * WINDOW_HEIGHT: new_keys.append('w') elif blob_pos[1] < 1.0 / 3.0 * WINDOW_HEIGHT: new_keys.append('s') if glfw.get_key(window, glfw.KEY_ENTER) == glfw.PRESS: new_keys.append('Escape') # Send press and release events when key state changes for char in ['w', 'a', 's', 'd', 'Escape']: new = char in new_keys old = char in old_keys if new: if not old: display.send_event(dest_window, keyev(char, True), event_mask=1) elif old: if not new: display.send_event(dest_window, keyev(char, False), event_mask=1) # Events don't get processed unless they are manually flushed while display.pending_events() > 0: display.poll_events() old_keys = new_keys
import Xlib.XK import Xlib.error import time display = Xlib.display.Display() screen = display.screen() root = screen.root pointer=root.query_pointer() #Get info like window where pointer is on and pointer position window=pointer.child ev_d = dict( time = 0, # Time of the event (useful for double-clicks for mouse events) root = root, window = pointer.child, #The window where is the pointer same_screen = 1,child = Xlib.X.NONE,root_x = pointer.root_x,root_y = pointer.root_y,event_x = pointer.win_x,event_y = pointer.win_y,state = Xlib.X.NONE,detail =Xlib.X.Button1 ) ev2_dict = ev_d.copy() ev2_dict['state'] = Xlib.X.Button1 # that is ButtonXMask ev=Xlib.protocol.event.ButtonPress(**ev_d) ev2=Xlib.protocol.event.ButtonRelease(**ev2_dict) display.send_event(Xlib.X.PointerWindow,ev) display.sync() # Send the inserted events time.sleep(500/1000) display.send_event(Xlib.X.PointerWindow,ev2) display.sync()