# This is pseudocode, illustrating a libei client implementation function main(): ctx = ei_new() ei_portal_connect(ctx) # let's say this is a blocking wait event = ei_get_event(); if ei_event_get_type(event) == EI_EVENT_TYPE_DISCONNECT: print("Sorry, server denied us") return # Could also create one device here with both caps but splitting them # means they can get suspended independently ptr = ei_create_device(ctx) ei_device_configure_capability(CAP_POINTER) ei_device_configure_name("pseudopointer") ei_device_add(ptr) kbd = ei_create_device(ctx) ei_device_configure_capability(CAP_KEYBOARD) ei_device_configure_name("pseudokeyboard"); keymap_fd = compile_keymap("us", "dvorak") ei_device_configure_keymap(kbd, FORMAT_XKB, keymap_fd); ei_device_add(kbd) event = ei_get_event() device = ei_event_get_device() if ei_event_get_type(event) == EI_EVENT_TYPE_DEVICE_ADDED: if device == ptr: # The server may not use the name we suggested but it does # tell us the chosen name print("Pointer was created: %s", ei_device_get_name(device)) else: print("Keyboard was created: %s", ei_device_get_name(device)) if ei_device_get_keymap_source != EI_KEYMAP_SOURCE_CLIENT: print("Server did not accept our keymap") # handle the keymap (if not -1) else if ei_event_get_type(event) == EI_EVENT_TYPE_DEVICE_REMOVED: if device == ptr: print("We're not allowed a pointer device") elif device == kbd: print("We're not allowed a keyboard device") # Our devices start in suspended mode suspended = True while True: poll(ei_get_fd()): if suspended: wait_for_event(EI_EVENT_DEVICE_RESUMED) wait_for_event(EI_EVENT_DEVICE_RESUMED) suspended = False continue event = ei_get_event(); handler = functions[ei_event_get_type(event)] handler(event) ei_disconnect(ctx) function event_disconnect(event): print("Ooops, the server kicked us off") ei_unref(ctx); sys.exit(1) function event_keyboard_keymap(event): # see README comments keymap_fd = ei_event_keyboard_get_keymap(event)) recompile_macros(keymap_fd) # Called by our actual application to emulate input function move_pointer(x, y): ei_device_pointer_motion(ptr, x, y) function macro(macro): for key in macro: ei_device_keyboard_key(kbd, key, true) msleep(12); # fake an interval ei_device_keyboard_key(kbd, key, false) msleep(12); # fake an interval