A program that just presses and releases the Esc key

reference

Check which event number the keyboard is

egrep "^(N|H)" /proc/bus/input/devices
ls -lh /dev/input/event5
crw-rw---- 1 root input 13,69 August 24 18:33 /dev/input/event5

A program that just presses and releases the Esc key

write.c


#include <stdio.h>
#include <stdlib.h>
#include <linux/input.h>
#include <sys/time.h>

void write_key_event(int code, int value, int fd)
{
        struct input_event key_event;

        gettimeofday(&key_event.time, NULL);
        key_event.type = EV_KEY;
        key_event.code = code;
        key_event.value = value;
        write(fd, &key_event, sizeof(key_event));
}

int main(void)
{
        write_key_event(KEY_ESC, 1, 1);
        write_key_event(KEY_ESC, 0, 1);

        //int i = 0;
        //int keys[] = { KEY_A ,KEY_B ,KEY_C };
        //while (keys[i] != '\0' ) {
        //      write_key_event(keys[i], 1, 1);
        //      write_key_event(keys[i], 0, 1);
        //      i++;
        //}

        //i = 0;
        //write_key_event(KEY_LEFTSHIFT, 1, 1);
        //while (keys[i] != '\0' ) {
        //      write_key_event(keys[i], 1, 1);
        //      write_key_event(keys[i], 0, 1);
        //      i++;
        //}
        //write_key_event(KEY_LEFTSHIFT, 0, 1);

        exit(EXIT_SUCCESS);
}

Run

gcc -o write.o write.c
./write.o > /dev/input/event5

Recommended Posts

A program that just presses and releases the Esc key
A program that answers a few questions and predicts the next answer
[Python] A program that rounds the score
A program that searches for the same image
A shell program that displays the Fibonacci sequence
[Python] A program that finds the minimum and maximum values without using methods
[Python] A program that calculates the number of updates of the highest and lowest records
[Python] A program that compares the positions of kangaroos.
A note that runs an external program in Python and parses the resulting line
A program that removes specific characters from the entered text
A shell script that just emails the SQL execution result
[Python] A program that finds the most common bird types
[Golang] A program that determines the turn with random numbers
[Python] A program to find the number of apples and oranges that can be harvested
A program that receives the servo command of the radio control, interrupts the Raspberry Pi and logs it
Understand the probabilities and statistics that can be used for progress management with a python program
When incrementing the value of a key that does not exist
I made a program that solves the spot the difference in seconds
[Ev3dev] Create a program that captures the LCD (screen) using python
I made a program that automatically calculates the zodiac with tkinter
[Python] A program that rotates the contents of the list to the left
The story of writing a program
[Python] A program that calculates the number of chocolate segments that meet the conditions
[Python] A program that calculates the number of socks to be paired
A program that will slowly recover the economy from any news headline
A python program that resizes a video and turns it into an image
[Python] A program that creates stairs with #
A class that hits the DMM API
A code that corrects the yoon / sokuon (sokuon)
A program that plays rock-paper-scissors using Python
Create a program that automatically inputs and sends body temperature every morning [Note]
Make a Python program a daemon and run it automatically when the OS starts
[pyqtgraph] Understand SignalProxy and create a crosshair that follows the cursor on the graph
An article that just tries a little HTTP request with the curl command
The story of making a box that interconnects Pepper's AL Memory and MQTT
A Python script that reads a SQL file, executes BigQuery and saves the csv
Publishing and using a program that automatically collects facial images of specified people
[Python] A program that calculates the difference between the total numbers on the diagonal line.
Is there a contradiction between the party that protects the people from NHK and the party that protects NHK from the people?