mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[feat] keyboard control supported on Windows
This commit is contained in:
@@ -8,4 +8,8 @@ int KeyboardCapturer::Hook(OnKeyAction on_key_action, void *user_ptr) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int KeyboardCapturer::Unhook() { return 0; }
|
int KeyboardCapturer::Unhook() { return 0; }
|
||||||
|
|
||||||
|
int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ class KeyboardCapturer : public DeviceController {
|
|||||||
public:
|
public:
|
||||||
virtual int Hook(OnKeyAction on_key_action, void *user_ptr);
|
virtual int Hook(OnKeyAction on_key_action, void *user_ptr);
|
||||||
virtual int Unhook();
|
virtual int Unhook();
|
||||||
|
virtual int SendKeyboardCommand(int key_code, bool is_down);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,4 +8,8 @@ int KeyboardCapturer::Hook(OnKeyAction on_key_action, void *user_ptr) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int KeyboardCapturer::Unhook() { return 0; }
|
int KeyboardCapturer::Unhook() { return 0; }
|
||||||
|
|
||||||
|
int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ class KeyboardCapturer : public DeviceController {
|
|||||||
public:
|
public:
|
||||||
virtual int Hook(OnKeyAction on_key_action, void *user_ptr);
|
virtual int Hook(OnKeyAction on_key_action, void *user_ptr);
|
||||||
virtual int Unhook();
|
virtual int Unhook();
|
||||||
|
virtual int SendKeyboardCommand(int key_code, bool is_down);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -51,5 +51,18 @@ int KeyboardCapturer::Hook(OnKeyAction on_key_action, void* user_ptr) {
|
|||||||
|
|
||||||
int KeyboardCapturer::Unhook() {
|
int KeyboardCapturer::Unhook() {
|
||||||
UnhookWindowsHookEx(keyboard_hook_);
|
UnhookWindowsHookEx(keyboard_hook_);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int KeyboardCapturer::SendKeyboardCommand(int key_code, bool is_down) {
|
||||||
|
INPUT input = {0};
|
||||||
|
input.type = INPUT_KEYBOARD;
|
||||||
|
input.ki.wVk = key_code;
|
||||||
|
|
||||||
|
if (!is_down) {
|
||||||
|
input.ki.dwFlags = KEYEVENTF_KEYUP;
|
||||||
|
}
|
||||||
|
SendInput(1, &input, sizeof(INPUT));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,7 @@ class KeyboardCapturer : public DeviceController {
|
|||||||
public:
|
public:
|
||||||
virtual int Hook(OnKeyAction on_key_action, void *user_ptr);
|
virtual int Hook(OnKeyAction on_key_action, void *user_ptr);
|
||||||
virtual int Unhook();
|
virtual int Unhook();
|
||||||
|
virtual int SendKeyboardCommand(int key_code, bool is_down);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HHOOK keyboard_hook_ = nullptr;
|
HHOOK keyboard_hook_ = nullptr;
|
||||||
|
|||||||
@@ -103,7 +103,9 @@ int Render::SendKeyEvent(int key_code, bool is_down) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Render::ProcessKeyEvent(int key_code, bool is_down) {
|
int Render::ProcessKeyEvent(int key_code, bool is_down) {
|
||||||
LOG_ERROR("key code [{}], is down [{}]", key_code, is_down);
|
if (keyboard_capturer_) {
|
||||||
|
keyboard_capturer_->SendKeyboardCommand(key_code, is_down);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user