Files
gKeyMapper/daemon/uinput_keyboard.h
2026-10-17 03:53:51 +02:00

39 lines
1023 B
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);
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