can python do some kernel stuff?

Diez B. Roggisch deets at nospam.web.de
Fri May 23 12:34:49 EDT 2008


Jimmy schrieb:
> On May 23, 11:14 pm, Jimmy <mcknight0... at gmail.com> wrote:
>> On May 23, 5:53 pm, "Diez B. Roggisch" <de... at nospam.web.de> wrote:
>>
>>
>>
>>> Jimmy schrieb:
>>>> On May 23, 3:05 pm, Andrew Lee <fiacre.patr... at gmail.com> wrote:
>>>>> Jimmy wrote:
>>>>>> Hi to all
>>>>>> python now has grown to a versatile language that can
>>>>>> accomplish tasks for many different purposes. However,
>>>>>> AFAIK, little is known about its ability of kernel coding.
>>>>>> So I am wondering if python can do some kernel coding that
>>>>>> used to be the private garden of C/C++. For example, can python
>>>>>> intercept the input of keyboard on a system level? someone told me
>>>>>> it's a kernel thing, isn't it?
>>>>> http://wiki.python.org/moin/elmer
>>>> well, straightly speaking, how can I know a key is pressed on a system-
>>>> level if
>>>> using python?
>>> What has that todo with kernel programming? You can use e.g. pygame to
>>> get keystrokes. Or under linux, read (if you are root) the keyboard
>>> input file - I've done that to support several keyboards attached to a
>>> machine.
>>> And the original question: no, python can't be used as kernel
>>> programming language. Amongst other reasons, performance & the GIL
>>> prevent that.
>>> Diez
>> sorry, my aim is not limited to one particular program. Yes, many
>> library can
>> permit you to respond to keyboard event, however, what I want is a
>> universal
>> function. as long as a key is pressed, no matter where, my program can
>> repond.
>>
>> I am quite strange with this topic. But according to my understanding,
>> any event, keyboard event
>> for example, once triggered, will be dilivered by keyboard driver to X
>> system, and then
>> any running program can either choose to respond or ignore. So my
>> question can be translated to:
>> how to make my program respond ?
> 
> maybe I'd better elaborate on my question. Back to my original
> question:
> intercept keyboard event on a system level. If you are writing program
> in
>  emacs, of course, the keyboard inputs are meant for emacs only. What
> I
> want is no matter what program you're running, keyboard events can be
> anyway caught by my program.
> 
> Am I clear with myself? :)

Do you want to intercept the call (prevent that it is passed through to 
e.g. emacs), or are you merely interested in getting it? If the latter, 
you can (as root) access the /dev/input keyboard device and get the 
scan-codes.

The former is more complicated - without research I don't know out of my 
head how to accomplish that. But it must be possible, as e.g. KDE 
observes global key-shortcuts. Most probably a X-server thing.



Diez



More information about the Python-list mailing list