I have a button connected to one of the GPIO pins. Can I emulate the keypress of keyboard key just writing its keycode to /dev/input/keyboard_device_file, when the button is presed?
Keyboard emulation via GPIO
Did you notice one of the "GPIO Buttons" or "Polled GPIO buttons" drivers in the kernel? I think one of them do exactly what you need.