Skip to content

localcc/hid_listener

Repository files navigation

hid_listener

HidListener is a library that allows you to listen to hid events cross-platform.

Windows

Add this into your main.cpp file

#include <hid_listener/hid_listener_plugin_windows.h>

and add this inside wWinMain funciton

HidListener listener;

MacOS

Add this into your MainFlutterWindow.swift file

import hid_listener

and add this inside MainFlutterWindow class

let listener = HidListener()

The file should now look something like this:

...
import hid_listener

class MainFlutterWindow: NSWindow {
  let listener = HidListener()
...

Linux

Add this into your main.cc file

#include <hid_listener/hid_listener_plugin.h>

and add this inside main funciton

HidListener listener;

Dart

To use the library, you first have to initialize the listener backend:

if (getListenerBackend() != null) {
  if (!getListenerBackend().initialize()) {
    print("Failed to initialize listener backend");
  }
} else {
  print("No listener backend for this platform")
}

After successfully initializing the listener backend, register listeners like this:

final keyboardListenerId = getListenerBackend()!.addKeyboardListener((event) {
  print("${event.logicalKey.debugName}")
});

getListenerBackend()!.addMouseListener((event) { ... })

Removing listeners can be done using remove(keyboard/Mouse)Listener method call:

getListenerBackend()!.removeKeyboardListener(keyboardListenerId);

About

Keyboard/Mouse event listener library for flutter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published