Ejemplo n.º 1
0
def create_keyboard_monitor(parent=None):
    """
    Create a new keyboard monitor:

    >>> monitor = create_keyboard_monitor(parent)
    >>> monitor.idle_time = 0.5
    >>> monitor.keys_to_ignore = monitor.IGNORE_MODIFIER_COMBOS
    >>> monitor.typingStarted.connect(lambda: print('typing started'))
    >>> monitor.typingStopped.connect(lambda: print('typing stopped'))
    >>> monitor.start()

    This function automatically chooses the "best" available implementation.
    Currently this means, that a :class:`RecordingKeyboardMonitor` is created,
    if the XRecord extension is available.  Otherwise this functions falls back
    to :class:`PollingKeyboardMonitor`.

    ``parent`` is the parent :class:`~PyQt4.QtCore.QObject`.

    Return an implementation of :class:`AbstractKeyboardMonitor`.
    """
    if xrecord:
        success, _ = xrecord.query_version(Display.from_qt())
        if success:
            return RecordingKeyboardMonitor(parent)
    return PollingKeyboardMonitor(parent)
Ejemplo n.º 2
0
def main():
    with Display.from_name() as display:
        _, xrecord_version = xrecord.query_version(display)
        print('xrecord version:', '.'.join(map(str, xrecord_version)))
        key_events = (xlib.KEY_PRESS, xlib.KEY_RELEASE)
        with xrecord.context(display, xrecord.ALL_CLIENTS,
                             device_events=key_events) as context:
            disable = disable_context_handler(context)
            signal.signal(signal.SIGINT, disable)
            signal.signal(signal.SIGTERM, disable)
            xrecord.enable_context(display, context, handle_event, None)
Ejemplo n.º 3
0
def main():
    with Display.from_name() as display:
        _, xrecord_version = xrecord.query_version(display)
        print('xrecord version:', '.'.join(map(str, xrecord_version)))
        key_events = (xlib.KEY_PRESS, xlib.KEY_RELEASE)
        with xrecord.context(display,
                             xrecord.ALL_CLIENTS,
                             device_events=key_events) as context:
            disable = disable_context_handler(context)
            signal.signal(signal.SIGINT, disable)
            signal.signal(signal.SIGTERM, disable)
            xrecord.enable_context(display, context, handle_event, None)
Ejemplo n.º 4
0
def test_query_version(display):
    success, version = xrecord.query_version(display)
    assert success
    assert version >= (1, 13)
Ejemplo n.º 5
0
def test_query_version(display):
    success, version = xrecord.query_version(display)
    assert success
    assert version >= (1, 13)