Files
gKeyMapper/daemon/uinput_keyboard.h
2026-10-18 03:50:33 +02:00

44 lines
1.3 KiB
C++

// gKeyMapper daemon - virtual keyboard for replaying "key" mappings.
#ifndef GKEYMAPPER_DAEMON_UINPUT_KEYBOARD_H
#define GKEYMAPPER_DAEMON_UINPUT_KEYBOARD_H
#include <vector>
#include "mapping.h"
namespace gkeymapper::daemon {
// A virtual keyboard created through /dev/uinput. It is only used to replay
// shortcuts; the daemon never reads from it.
class UinputKeyboard {
public:
UinputKeyboard() = default;
~UinputKeyboard();
UinputKeyboard(const UinputKeyboard&) = delete;
UinputKeyboard& operator=(const UinputKeyboard&) = delete;
bool open();
void close();
bool is_open() const { return fd_ >= 0; }
// Presses and releases every step of the shortcut in order.
void play(const std::vector<gkeymapper::ShortcutStep>& steps);
// Presses and releases a single Linux key code. The media keys are replayed
// with this: the keyboard reports them on its own (see README), so the daemon
// passes them on unchanged instead of turning them into a mapping.
void tap(unsigned short code);
private:
void emit(unsigned short type, unsigned short code, int value);
void sync();
void key_event(unsigned short code, bool down);
int fd_ = -1;
};
} // namespace gkeymapper::daemon
#endif // GKEYMAPPER_DAEMON_UINPUT_KEYBOARD_H