Skip to content
Open
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
76 changes: 76 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"files.associations": {
"algorithm": "cpp",
"any": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"charconv": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"exception": "cpp",
"format": "cpp",
"forward_list": "cpp",
"functional": "cpp",
"future": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"iterator": "cpp",
"limits": "cpp",
"list": "cpp",
"locale": "cpp",
"map": "cpp",
"memory": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"set": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"thread": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"utility": "cpp",
"variant": "cpp",
"vector": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp"
}
}
13 changes: 7 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ void mouseListener(MouseEvent event) {
var registerResult = "";

void main() {
if (!getListenerBackend()!.initialize()) {
print("Failed to initialize listener backend");
bool initialized = getListenerBackend()!.doInit();
if (!initialized) {
registerResult = "Failed to initialize listener backend";
} else {
getListenerBackend()!.addKeyboardListener(listener);
getListenerBackend()!.addMouseListener(mouseListener);
registerResult = "Initialized listener backend";
}

getListenerBackend()!.addKeyboardListener(listener);
getListenerBackend()!.addMouseListener(mouseListener);

runApp(const MyApp());
}

Expand Down
2 changes: 2 additions & 0 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import FlutterMacOS
import Foundation

import firebase_core
import hid_listener

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
HidListenerPlugin.register(with: registry.registrar(forPlugin: "HidListenerPlugin"))
}
63 changes: 50 additions & 13 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.17.2"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -65,6 +65,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.0"
firebase_core:
dependency: "direct main"
description:
name: firebase_core
sha256: "7706f4ade6cc2698c70074083bc262586a185047f6bfdd53938dcc35d35cbb9e"
url: "https://pub.dev"
source: hosted
version: "2.21.0"
firebase_core_platform_interface:
dependency: transitive
description:
name: firebase_core_platform_interface
sha256: c437ae5d17e6b5cc7981cf6fd458a5db4d12979905f9aafd1fea930428a9fe63
url: "https://pub.dev"
source: hosted
version: "5.0.0"
firebase_core_web:
dependency: transitive
description:
name: firebase_core_web
sha256: "0631a2ec971dbc540275e2fa00c3a8a2676f0a7adbc3c197d6fba569db689d97"
url: "https://pub.dev"
source: hosted
version: "2.8.1"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -83,13 +107,18 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
hid_listener:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "1.1.3"
version: "2.0.1"
js:
dependency: transitive
description:
Expand All @@ -110,18 +139,18 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -155,10 +184,10 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
Expand Down Expand Up @@ -195,10 +224,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.6.0"
vector_math:
dependency: transitive
description:
Expand All @@ -207,6 +236,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
sdks:
dart: ">=3.0.0 <4.0.0"
flutter: ">=2.5.0"
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=3.3.0"
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies:
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../

firebase_core: ^2.21.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
Expand Down
3 changes: 3 additions & 0 deletions example/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

#include "generated_plugin_registrant.h"

#include <firebase_core/firebase_core_plugin_c_api.h>
#include <hid_listener/hid_listener_plugin_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FirebaseCorePluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FirebaseCorePluginCApi"));
HidListenerPluginWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("HidListenerPluginWindows"));
}
1 change: 1 addition & 0 deletions example/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
firebase_core
hid_listener
)

Expand Down
11 changes: 11 additions & 0 deletions lib/src/hid_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ abstract class HidListenerBackend {
mouseListeners.remove(listenerId);
}

bool doInit() {
const MethodChannel pluginChannel = MethodChannel("hid_listener");
pluginChannel.invokeMethod("Initialize");
return initialize();
}

void doDispose() {
const MethodChannel pluginChannel = MethodChannel("hid_listener");
pluginChannel.invokeMethod("Dispose");
}

bool initialize();
bool registerKeyboard();
bool registerMouse();
Expand Down
11 changes: 8 additions & 3 deletions windows/hid_listener_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <sstream>

namespace hid_listener {

// static
void HidListenerPlugin::RegisterWithRegistrar(
flutter::PluginRegistrarWindows *registrar) {
Expand All @@ -36,7 +35,6 @@ void HidListenerPlugin::RegisterWithRegistrar(
HidListenerPlugin::HidListenerPlugin() {}

HidListenerPlugin::~HidListenerPlugin() {}

void HidListenerPlugin::HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue> &method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
Expand All @@ -51,7 +49,14 @@ void HidListenerPlugin::HandleMethodCall(
version_stream << "7";
}
result->Success(flutter::EncodableValue(version_stream.str()));
} else {
}
else if (method_call.method_name().compare("Initialize") == 0) {
printf("HidListenerPlugin::HandleMethodCall: Initialize\n");
}
else if (method_call.method_name().compare("Dispose") == 0) {
printf("HidListenerPlugin::HandleMethodCall: Dispose\n");
}
else {
result->NotImplemented();
}
}
Expand Down
11 changes: 5 additions & 6 deletions windows/hid_listener_plugin_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,32 @@ static LRESULT MouseProc(int nCode, WPARAM wParam, LPARAM lParam) {
}

#if defined(__cplusplus)

HidListener* HidListener::listenerInstance = nullptr;
HidListener* ListenerInstance = nullptr;

HidListener::HidListener() {
m_keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, NULL, NULL);
m_mouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, NULL, NULL);

listenerInstance = this;
ListenerInstance = this;
}

HidListener::~HidListener() {
UnhookWindowsHookEx(m_keyboardHook);
UnhookWindowsHookEx(m_mouseHook);

listenerInstance = nullptr;
ListenerInstance = nullptr;
}

#endif

bool SetKeyboardListener(Dart_Port port) {
if(HidListener::Get() == nullptr) return false;
if(ListenerInstance == nullptr) return false;
keyboardListenerPort = port;
return true;
}

bool SetMouseListener(Dart_Port port) {
if(HidListener::Get() == nullptr) return false;
if(ListenerInstance == nullptr) return false;
mouseListenerPort = port;
return true;
}
Expand Down
5 changes: 0 additions & 5 deletions windows/include/hid_listener/hid_listener_plugin_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ extern "C"
public:
HidListener();
~HidListener();

static HidListener* Get() { return HidListener::listenerInstance; }

private:
HHOOK m_keyboardHook;
HHOOK m_mouseHook;

static HidListener* listenerInstance;
};
#endif

Expand Down