Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio, evdev
- import itertools
- import subprocess
- KEY_SPACE = 57
- KEY_SYM = 162
- keys_pressed = {
- KEY_SPACE: 0,
- KEY_SYM: 0,
- }
- layouts = ['us', 'ru']
- cmd = "dconf write /desktop/lipstick-jolla-home/layout '{layout_code}'"
- @asyncio.coroutine
- def layout_switcher(device):
- layouts_pool = itertools.cycle(layouts)
- layout_code = next(layouts_pool)
- print('Current layout is {}'.format(layout_code))
- set_layout(layout_code)
- while True:
- events = yield from device.async_read()
- for event in events:
- if event.type == evdev.ecodes.EV_KEY:
- # Sym + space
- if event.code in (KEY_SPACE, KEY_SYM):
- keys_pressed[event.code] = event.value
- if keys_pressed[KEY_SPACE] and keys_pressed[KEY_SYM]:
- layout_code = next(layouts_pool)
- print('Switching keyboard layout to {}'.format(layout_code))
- set_layout(layout_code)
- def set_layout(layout_code):
- layout_cmd = cmd.format(layout_code=layout_code).split()
- subprocess.call(layout_cmd)
- keybd = evdev.InputDevice('/dev/input/event3')
- asyncio.async(layout_switcher(keybd))
- loop = asyncio.get_event_loop()
- loop.run_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement