1 /*
2     This file is part of libuInputPlus.
3     Copyright (C) 2018 YukiWorkshop
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the MIT License.
7 
8     This program is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 */
12 
13 #ifndef LIBUINPUTPLUS_UINPUT_HPP
14 #define LIBUINPUTPLUS_UINPUT_HPP
15 
16 #include "CommonIncludes.hpp"
17 #include "uInputSetup.hpp"
18 
19 namespace uInputPlus {
20 
21 	struct uInputRawData {
22 		uint16_t type;
23 		uint16_t code;
24 		int32_t value;
25 	} __attribute__((packed));
26 
27     class uInputCoordinate {
28     public:
29 	int32_t X = 0, Y = 0, Z = 0;
30 
31 	uInputCoordinate() = default;
uInputCoordinate(int32_t x,int32_t y)32 	uInputCoordinate(int32_t x, int32_t y) {
33 		X = x; Y = y;
34 	}
uInputCoordinate(int32_t x,int32_t y,int32_t z)35 	uInputCoordinate(int32_t x, int32_t y, int32_t z) {
36 		X = x; Y = y; Z = z;
37 	}
38     };
39 
40     class uInput {
41     private:
42     	int (*custom_callback)(uint16_t type, uint16_t code, int32_t val, void *userp) = nullptr;
43     	void *custom_data = nullptr;
44 
45 
46     public:
47 	uInput() = default;
48 	uInput(const uInputSetup &setup);
49 	~uInput();
50 
51 	int FD = -1;
52 
53 	void Init(const uInputSetup &setup);
54 	void Init(int (*__custom_callback)(uint16_t type, uint16_t code, int32_t val, void *userp), void *__userp);
55 	void Destroy();
56 
57 	void Emit(uint16_t type, uint16_t code, int32_t val) const;
58 
59 	void SendKey(uint16_t key_code, uint32_t value, bool report = true) const;
60 	void SendKeyPress(const std::initializer_list<uint16_t> &keycodes, bool report = true) const;
61 	void SendKeyPress(std::vector<std::pair<int, int>> keys, bool report = true) const;
62 
63 	void RelativeMove(const uInputCoordinate &movement, bool report = true) const;
64 	void RelativeWheel(int32_t movement, bool h = false, bool report = true) const;
65 
66 	void AbsolutePosition(const uInputCoordinate &pos, int32_t mt_slot = -1, bool report = true) const;
67 	void AbsoluteWheel(int32_t movement, bool report = true) const;
68 
69 	void EmulateSmoothScroll(int offset, bool report = true) const;
70 
71     };
72 }
73 
74 #endif //LIBUINPUTPLUS_UINPUT_HPP