Hello world

'''
Creates a virtual output keyboard device and types "Hello world!" on it.
'''
import map2
import time

map2.default(layout = "us")

reader = map2.Reader()
writer = map2.Writer(capabilities = {"keys": True})

map2.link([reader, writer])

reader.send("Hello world!")

# keep running for 1sec so the event can be processed
time.sleep(1)

To emmit custom events, we need an output device, so we create a virtual one using Writer. The device needs the keys capability in order to emmit keyboard key events.

Since we don’t want to intercept a physical input device, but instead send events programatically, we create a Reader.

Finally we need to link the input and output devices, so events can flow.