logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: Keys and scancodes: msg#00001

Subject: Re: Keys and scancodes
On Wed, Sep 20, 2006 at 02:56:41PM +0200, Konstantin Tcholokachvili wrote:
> Hello,
> 
> I'm trying to code a module which handles keyboard events (such as: "a 
> pressed","a released','ctrl pressed"...).
> It will be useful for a text editor and other event-driven applications.
> But the method I coded return me always the number "1" instead of the 
> scancode
> of a key. The code below is inspired by keyboard.asm and hydro3d.asm. I 
> modified it again and again but it only  returns "1". Can a 
> knowledgeable person help me to fix it?
> 
>               Narke.
> 
> ------------------------ begin-------------------------
> 
> #include <python2.3/Python.h>
> 
> static PyObject *get_scancode(PyObject *self, PyObject *args)
> {
>    char scancode;
> 
> 
>    asm volatile(
>        "cli\n"              /* Clear interruptions */
>        "push %%eax\n"
>        "push %%ebx\n"
>        "xor %%eax,%%eax\n"    /* Set eax to zero */
>        ".wait4buffer:\n"
>            "inb $0x64,%%al\n"   /* To know the status of the keyboard */
>            "testb $0x01,%%al\n"  /* Is the keyboard buffer empty? */
>            "jz .wait4buffer\n"      /* Yes, wait! */
>        "inb $0x60,%%al\n"    /* No, let's read the input to get the 
> scancode! */
>        "pop %%ebx\n"
>        "pop %%eax\n"
>        "sti\n"        /* Set interruptions */
>        :"=a"(scancode)
>       );
> 
>    scancode = scancode & 0xff;
> 
>    return Py_BuildValue("b",scancode);
> }
> 
> static PyMethodDef AaaMethods[] = {
>    {"get_scancode", get_scancode, METH_VARARGS,"Get the scancode of a 
> key"},
>    {NULL, NULL, 0, NULL}
> };
> 
> void init_aaamodule() {
>    Py_InitModule( "aaa", AaaMethods );
> }
> 
> ------------------------ end-------------------------

Looks like the asm block pushes eax, reads the scancode into al, and
then pops eax, overwriting the scancode.


<Prev in Thread] Current Thread [Next in Thread>