Skip to content
This repository has been archived by the owner. It is now read-only.
libtermkey Python ctypes bindings
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



Python ctypes bindings for libtermkey,
one excellent terminal key handling library.


See for a simple demo
(to exit press C-c, that is Control+C).


To use bindings, you must first install libtermkey.

Then, you can import TermKey from ctypes_termkey.

!!! TermKey() causes Segmentation Fault in python interpreter. !!!
***WARNING*** for some reason, cpython interpreter segfaults when
you're trying to instantiate TermKey, that is, when libtermkey is
initializing. So everything described below is what you should try
in your existing program or write brand new.
For this reason, examples described here, start Python code lines
with {{{ and end them with }}}, like in Trac.

    from ctypes_termkey import TermKey

if all goes ok, you'll see no errors here.
You can now instantiate TermKey class to start using libtermkey.

    tk = TermKey()

Actually, you could pass two parameters to constructor:
    file descriptor and flags.
# TODO: document parameters
Now you can start collecting keys, i.e. in wait mode:

    result, key = tk.waitkey()

result corresponds to ctypes_termkey.Result class attributes:
key corresponds to ctypes_termkey.termkey_key structure.

    from ctypes_termkey import Result
    if result == Result.KEY:
        print "got key"

to get string key name from key you can call the sprint() method.

    print tk.sprint_key(key)

which could print, i.e., q.
Look at termkey documentation to learn how to use it.


Bindings by Sergey Shepelev <>
libtermkey by Paul LeoNerd Evans <>
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.