Keyboard Creation

How to make a simple C-program that will produce keyboard keystrokes.

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

I am working on Linux OS Ubuntu 8.10

+3
source share
6 answers

Get fake key events with 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;
}
0
source

Here is a simple example of using libxdo (from xdotool). (Caution: I am the author of xdotool)

 /* File: testkey.c
 *
 * Compile with:
 * gcc -lxdo testkey.c
 *
 * Requires libxdo (from xdotool project)
 */

#include <xdo.h>

int main() {
  xdo_t *xdo = xdo_new(NULL);
  xdo_keysequence(xdo, CURRENTWINDOW, "A", 0);
  return  0;
}
+15
source
+2
+2

C, Java:

import java.awt.Robot;
import java.awt.AWTException;
import java.awt.event.KeyEvent;


public class key
{
    public static void main(String args[])
    {
        try {
            Robot r = new Robot();
            r.delay(2000);
            r.keyPress(KeyEvent.VK_W);
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }
};
+2

Swinput.

Swinput can fake a mouse and keyboard using the Linux system input. Movable modules are read from the device and fake a hardware event (mouse movement, keystrokes, etc.), like commands recorded on devices.

0
source

Source: https://habr.com/ru/post/1712288/


All Articles