Search code examples
clinuxubuntukeyboardubuntu-8.10

Produce keyboard Events key hits


How to make a simple C program which will produce keyboard key hits.

if ( condition ) {
    KeyPress('A');
}

I am working on Ubuntu 8.10 Linux OS


Solution

  • Get Fake Key Events by Xdotool

    //Compile As:  gcc button.c -lX11 
    
    #include < X11/Xlib.h >
    #include < X11/Xutil.h >
    #include < stdio.h >
    #include < X11/extensions/XTest.h >
    
    void press_button()
    {   
        Display *d;
        d = XOpenDisplay(NULL);
            if(d == NULL)
            {
                //fprintf(stderr, "Errore nell'apertura del Display !!!\n");
                //exit(0);
            }
        system("xdotool key Shift+a");
        XFlush(d);
        XCloseDisplay(d);
    }
    
    int main() {
        press_button();
        return 0;
    }