Git Product home page Git Product logo

animeshz / keyboard-mouse-kt Goto Github PK

View Code? Open in Web Editor NEW
52.0 1.0 2.0 1.85 MB

A lightweight multiplatform library for interacting with global keyboard and mouse events and states from Kotlin, Java and NodeJS.

Home Page: https://animeshz.github.io/keyboard-mouse-kt

License: MIT License

Kotlin 72.79% Dockerfile 2.14% CMake 2.84% C++ 21.84% Java 0.39%
mouse-events keyboard multiplatform-kotlin-library kotlin keyboard-events keyboard-state keyboard-hooks hotkey mouse multiplatform

keyboard-mouse-kt's Introduction

KeyboardMouse.kt

Docs: Click Here Discord: Chat here Latest Release Code Size License

What is KeyboardMouse.kt

KeyboardMouse.kt is a lightweight, coroutine-based multiplatform kotlin library for idiomatically interacting with Keyboard and Mouse (receiving and sending global events) from Kotlin, Java and NodeJS.

We aim to provide high-level as well as high-performant low-level access to such APIs. See the documentation below to know more!

Documentation and more

To learn more about KeyboardMouse.kt, visit animeshz.github.io/keyboard-mouse-kt.

keyboard-mouse-kt's People

Contributors

animeshz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

keyboard-mouse-kt's Issues

Implementation of Linux's DeviceKeyboardHandler.

Only X11 based linux distro is supported right now, if the X11 is not accessible (though should be in most GUI distros), we can safely fallback to read events from the /dev/uinput or /dev/input/eventX.

This operation is only granted when the root access is given, so we'll always prioritize the X11 way to handle the communication.

To be fixed: DeviceKeyboardHandler.

Mac OS support

Need collaborators / contributors for testing and working on extending the library to support Mac OS.

Unfortunately I have zero experience with Apple products and don't have access to a Mac right now, so I couldn't test the library either way.

The codebase is organized to easily integrate the support, one can work on either Java, C++ (JNI side) or Kotlin (K/Native side) whichever is more familiar to him/her. The keyboard-kt/src/jvmMain/jni/{platform}-{arch}/ is where the platform specific JNI code reside, and the Kotlin/Native code is present in keyboard-kt/src/{platform}{arch}Main/ as usual.

To cross-build for the JVM packaging we can use multiarch/crossbuild, and gradle to automate the build process as we've did for Windows and Linux currently.

If somebody has any idea or suggestions drop it below! A small contribution may help the project to pick up the momentum to get ready for the complete implementation.

Feature: To add a flexible way to specify more than 1 key combination (KeySet)

Current implementation only allows to specify one KeySet when calling some function in the Keyboard.

But that's not really idiomatic, in sense that we may want to do something like (Key.LeftCtrl or Key.RightCtrl) + K combination, in this case we can add two different handler for that (or create a lambda in a variable and call the function twice), but in some parts like suspensive waiting for key combination(s) to be pressed it is quite cumbersome.

Similarly if we want something like (Key.LeftCtrl or Key.RightCtrl) + (Key.LeftShift or Key.RightShift) + G the code becomes multiplicative large (i.e. setting the handler 4 times).

So the issue is clear, to implement a flexible way to pass a generic KeyCombination which is different from KeySet and allows to interact with the high-level api in even more convenient way!

Bug: NativeKeyboardHandler.sendEvent() doesn't work in Linux x64 (both on JVM & Native).

Unexpectedly the X11 events are not able to dispatch properly, the root cause is unknown. I've asked a question on StackOverflow but didn't got a meaningful reply. Maybe we need to dig deeper why doesn't XSendEvent work.

Affected code:

void sendEvent(int scanCode, bool isPressed) {
unsigned long focusedWindow;
int focusRevert;
int mask = isPressed ? KeyPressMask : KeyReleaseMask;
XGetInputFocus(display, &focusedWindow, &focusRevert);
XKeyEvent event;
memset(&event, 0, sizeof(XKeyEvent));
event.keycode = scanCode + 8;
event.type = isPressed ? KeyPress : KeyRelease;
event.root = focusedWindow;
event.display = display;
XSendEvent(display, focusedWindow, 1, mask, (XEvent *)&event);
XSync(display, 0);
}

Keyboard event receiving part in JVM is implemented incorrectly.

In windows, all the work (from hooking to unhooking) must be done in single thread or else, the system becomes very slow and laggy, and hook doesn't work as expected.

EXCEPTION_ACCESS_VIOLATION is also generated, need to recheck things. This generally occurs when local references of JNI are stored in shared library.

Migrate to dynamic library linking for linux, effectively supporting systems without X11.

Currently using the XLib and XInput2 requires the overhead of installing the required lib to generate the headers which does not let non-linux host or one without these libs to build the project for those platform.

Second most important thing is that where there is non-X11 desktop environment the library won't work. Which limits it in the amount of targets.

Future plan is to migrate all the c-interop generated stubs into dlopen/dlsym/dlclose Posix API which allows to dynamically fetch the CPointer<CFunction<*>> and invoke it. Which can be done in the runtime (and has pretty less runtime overhead), we may even cache it at the first access.

This will let the library to be build without headers and in Windows/Mac for Linux as well and and can easily test it remotely on a VM. This will also enable to fallback to the Linux device API (/dev/uinput | /dev/input/xxx) if X11 is not present, which will allow the lib to support almost all the linux platforms (though this device API requires superuser).

Switch to our own single and minimal docker image for building all of the required targets.

Getting dockcross images might be a pain, it includes 450mb compressed images for each x86 and x86_64 linux images, and 650mb each of the windows build images (actually are linux, but has build tools).

And the uncompressed size is about twice of each of them, so are not very feasible to pull large amount of data before building things even if they are automated.

Instead we can create a docker image of our own which has all the tools in it, and can be compressed down to as small as possible to make it easy to build the project for jvm and nodejs.

"Expected a Boolean" error occurred while sending events through NodeJS.

Affected files:

void Send(const Napi::CallbackInfo& info) {
int scanCode = info[0].As<Napi::Number>().Int32Value();
bool isPressed = info[0].As<Napi::Boolean>().Value();

void Send(const Napi::CallbackInfo& info) {
int scanCode = info[0].As<Napi::Number>().Int32Value();
bool isPressed = info[0].As<Napi::Boolean>().Value();

The index number 0 is used twice by mistake, a quick-fix can be added.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.