Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libs/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ target_sources(
include/quite/value/generic_value_class.hpp
include/quite/value/object_query.hpp
include/quite/injectors/mouse_injector.hpp
include/quite/injectors/keyboard_injector.hpp
FILE_SET export_config
TYPE HEADERS
BASE_DIRS ${CMAKE_CURRENT_BINARY_DIR}
Expand Down
8 changes: 8 additions & 0 deletions libs/core/include/quite/injectors/keyboard.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

namespace quite::core
{
enum class KeyboardKey
{
};
} // namespace quite::core
21 changes: 21 additions & 0 deletions libs/core/include/quite/injectors/keyboard_injector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include <unordered_set>
#include "keyboard.hpp"
#include "quite/async_result.hpp"
#include "quite/quite_core_export.hpp"
#include "quite/value/object_id.hpp"

namespace quite::core
{

class QUITE_CORE_EXPORT IKeyboardInjector
{
public:
using KeyStates = std::unordered_set<KeyboardKey>;
virtual ~IKeyboardInjector() = default;
virtual AsyncResult<KeyStates> press(ObjectId target_id, KeyboardKey key) = 0;
virtual AsyncResult<KeyStates> release(ObjectId target_id, KeyboardKey key) = 0;
virtual AsyncResult<KeyStates> press_and_release(ObjectId target_id, KeyboardKey key) = 0;
virtual AsyncResult<void> press_and_release_each(ObjectId target_id, std::string keys) = 0;
};
} // namespace quite::core
12 changes: 12 additions & 0 deletions libs/probeqt/injector/keyboard_injector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "keyboard_injector.hpp"
#include <QKeyEvent>
namespace quite::probe
{
KeyboardInjector::KeyboardInjector()
{
// https://codebrowser.dev/qt6/qtbase/src/testlib/qasciikey.cpp.html#_ZN5QTest10asciiToKeyEc
QKeyEvent{QEvent::Type::KeyPress, Qt::Key_Shift, {}};
QKeyEvent{QEvent::Type::KeyPress, Qt::Key_A, {}};
QKeyEvent{QEvent::Type::KeyPress, Qt::Key_A, {}};
}
} // namespace quite::probe
11 changes: 11 additions & 0 deletions libs/probeqt/injector/keyboard_injector.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include <quite/injectors/keyboard_injector.hpp>

namespace quite::probe
{
class KeyboardInjector : public core::IKeyboardInjector
{
public:
KeyboardInjector();
};
} // namespace quite::probe
1 change: 1 addition & 0 deletions libs/protocol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ asio_grpc_protobuf_generate(
"${proto_inc_dir}/common.proto"
"${proto_inc_dir}/probe.proto"
"${proto_inc_dir}/keyboard.proto"
"${proto_inc_dir}/keyboard_service.proto"
"${proto_inc_dir}/mouse.proto"
"${proto_inc_dir}/types.proto"
"${proto_inc_dir}/methods.proto"
Expand Down
6 changes: 4 additions & 2 deletions libs/protocol/include/quite/proto/probe/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class ValueRegistry;
namespace quite::core
{
class IMouseInjector;
}
class IKeyboardInjector;
} // namespace quite::core
namespace quite::meta
{
class MetaRegistry;
Expand All @@ -30,7 +31,8 @@ class QUITE_PROTOCOL_EXPORT Server final
ServiceHandle<IProbeHandler> probe_handler,
ServiceHandle<core::IMouseInjector> mouse_injector,
ServiceHandle<meta::MetaRegistry> meta_registry,
ServiceHandle<ValueRegistry> value_registry);
ServiceHandle<ValueRegistry> value_registry,
ServiceHandle<core::IKeyboardInjector> keyboard_injector = {});
Server(Server &&server) noexcept;
Server &operator=(Server &&server) noexcept;
~Server();
Expand Down
13 changes: 4 additions & 9 deletions libs/protocol/quite/proto/keyboard.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ syntax = "proto3";

package quite.proto;

enum KeyboardModifierKey {
no_mod = 0;
shift = 1;
crtl = 2;
alt = 3;
meta = 4;
keypad = 5;
}

enum KeyboardKey {
no_key = 0;
escape = 1;
tab = 2;
backspace = 3;
return = 4;
shift = 5;
crtl = 6;
alt = 7;
meta = 8;
}
23 changes: 23 additions & 0 deletions libs/protocol/quite/proto/keyboard_service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
syntax = "proto3";
package quite.proto;
import "quite/proto/keyboard.proto";

service KeyboardService {
rpc PressKey(KeyRequest) returns (KeyResponse) {}
rpc ReleaseKey(KeyRequest) returns (KeyResponse) {}
rpc PressAndReleaseKey(KeyRequest) returns (KeyResponse) {}
rpc PressAndReleaseEach(KeySequenceRequest) returns (KeyResponse) {}
}

message KeyRequest {
KeyboardKey key = 1;
}

message KeySequenceRequest {
KeyboardKey key = 1;
}

message KeyResponse {
// the list of keys which are currently in pressed state
repeated KeyboardKey pressed_keys = 1;
}
2 changes: 1 addition & 1 deletion libs/protocol/quite/proto/probe.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ message MouseActionRequest {
uint64 object_id = 1;
MouseAction mouse_action = 2;
MouseButton mouse_button = 3;
optional KeyboardModifierKey modifier_key = 4;
optional KeyboardKey modifier_key = 4;
// delay between press and release
optional uint32 delay_ms = 5;
// the (click) point relative to the object coordinates.
Expand Down
6 changes: 2 additions & 4 deletions libs/protocol/src/probe/rpc_mouse_injection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ quite::core::MouseAction mouse_action_from_request(const quite::proto::MouseActi
[modifier = request.modifier_key()]() {
switch (modifier)
{
case quite::proto::no_mod:
case quite::proto::no_key:
return quite::core::KeyboardModifier::none;
case quite::proto::shift:
return quite::core::KeyboardModifier::shift;
Expand All @@ -65,9 +65,7 @@ quite::core::MouseAction mouse_action_from_request(const quite::proto::MouseActi
return quite::core::KeyboardModifier::alt;
case quite::proto::meta:
return quite::core::KeyboardModifier::meta;
case quite::proto::keypad:
case quite::proto::KeyboardModifierKey_INT_MIN_SENTINEL_DO_NOT_USE_:
case quite::proto::KeyboardModifierKey_INT_MAX_SENTINEL_DO_NOT_USE_:
default:
break;
}
return quite::core::KeyboardModifier::none;
Expand Down
10 changes: 9 additions & 1 deletion libs/protocol/src/probe/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <exec/finally.hpp>
#include <quite/logger.hpp>
#include <quite/proto/health.grpc.pb.h>
#include <quite/proto/keyboard_service.grpc.pb.h>
#include <quite/proto/meta_service.grpc.pb.h>
#include <quite/proto/probe.grpc.pb.h>
#include "rpc_fetch_windows.hpp"
Expand All @@ -26,6 +27,7 @@ class Server::Impl
stdexec::inplace_stop_source ssource_;
ServiceHandle<IProbeHandler> probe_handler_;
ServiceHandle<core::IMouseInjector> mouse_injector_;
ServiceHandle<core::IKeyboardInjector> keyboard_injector_;
ServiceHandle<meta::MetaRegistry> meta_registry_;
ServiceHandle<ValueRegistry> value_registry_;
grpc::ServerBuilder builder_;
Expand All @@ -37,10 +39,12 @@ class Server::Impl
Impl(std::string server_address,
ServiceHandle<IProbeHandler> probe_handler,
ServiceHandle<core::IMouseInjector> mouse_injector,
ServiceHandle<core::IKeyboardInjector> keyboard_injector,
ServiceHandle<meta::MetaRegistry> meta_registry,
ServiceHandle<ValueRegistry> value_registry)
: probe_handler_{std::move(probe_handler)}
, mouse_injector_{std::move(mouse_injector)}
, keyboard_injector_{std::move(keyboard_injector)}
, meta_registry_{std::move(meta_registry)}
, value_registry_{std::move(value_registry)}
, grpc_runner_{[this, server_address = std::move(server_address)]() {
Expand Down Expand Up @@ -68,9 +72,11 @@ class Server::Impl

ProbeService::AsyncService object_service;
MetaService::AsyncService meta_service;
KeyboardService::AsyncService keyboard_service;

builder_.RegisterService(std::addressof(object_service));
builder_.RegisterService(std::addressof(meta_service));
builder_.RegisterService(std::addressof(keyboard_service));
agrpc::add_health_check_service(builder_);

grpc_server_ = builder_.BuildAndStart();
Expand Down Expand Up @@ -123,10 +129,12 @@ Server::Server(std::string server_address,
ServiceHandle<IProbeHandler> probe_handler,
ServiceHandle<core::IMouseInjector> mouse_injector,
ServiceHandle<meta::MetaRegistry> meta_registry,
ServiceHandle<ValueRegistry> value_registry)
ServiceHandle<ValueRegistry> value_registry,
ServiceHandle<core::IKeyboardInjector> keyboard_injector)
: impl_{std::make_unique<Impl>(std::move(server_address),
std::move(probe_handler),
std::move(mouse_injector),
std::move(keyboard_injector),
std::move(meta_registry),
std::move(value_registry))}
{}
Expand Down
Empty file.
Empty file.
Loading