Giter Site home page Giter Site logo

gkm's Introduction

GKM

An event based, Global Keyboard and Mouse listener.

Tested on Windows 7, but should work on Linux and Mac OS X as well (untested).

NPM

Why?

Node didn't have any global keyboard and mouse listener available at the time.

Requirements

GKM depends on JNativeHook, which runs on Java. Thus you will need to have a JVM available and more importantly, java availble on your PATH.

In the lib folder, you will find gkm.jar, which source you can find at https://github.com/tomzx/gkm-java. You will also find JNativeHook.jar, which source you can find at https://github.com/kwhat/jnativehook.

Getting started

Install gkm via node.js package manager:

npm install gkm --save

Then require the package in your code:

var gkm = require('gkm');

// Listen to all key events (pressed, released, typed)
gkm.events.on('key.*', function(data) {
    console.log(this.event + ' ' + data);
});

// Listen to all mouse events (click, pressed, released, moved, dragged)
gkm.events.on('mouse.*', function(data) {
	console.log(this.event + ' ' + data);
});

License

The code is licensed under the MIT license (http://opensource.org/licenses/MIT). See license.txt.

gkm's People

Contributors

tomzx 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  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gkm's Issues

Mouse Wheel

In "JNativeHook.jar" demo on Gkm's directory we can view mouse wheel's data, but even listen to every events on Gkm's module ( gkm.events.onAny(function(data) {console.log(this.event+' '+data);}); ) there is no mouse wheel's data =(. I checked gkm-java source and look to me that there is no emitter to JNativeHooks's "NativeMouseWheelListener", I don't know plenty Java and can be completely wrong.
Is this data available on Gkm.js? How can I help develop this functionality if there isn't?
Thank you for this package, It's the only one that satisfy my needs on Windows 10, and I realy want to only depends on it! English is not my mother tongue; please excuse any errors on my part =).

event.data includes a newline

(tested on Kubuntu 15)
Awesome module, but unfortunately every event includes a newline in the data field.

index.js

var gkm = require('gkm');

gkm.events.on('key.pressed', function (data) {
    console.log('\'' + data + '\'')
    console.log(this.event + ' ' + data);
});

output

'D
'
key.pressed D

Guess that's not intended, makes it much harder to work with at least.

Publish the latest v0.3.0 to NPM

Can you publish the latest v0.3.0 to NPM? Currently "newest" version on NPM is v0.1.0 and this version doesn't support mouse wheel events. I had to manually replace gkm.jar from the latest v0.3.0 release.

Global hook not working properly

The current version of jNativeHook (1.1.4) will stop working properly on Windows after some event (still unknown).

When it breaks, the OS global hotkeys such as F2 to edit a filename do not work anymore. The current only known fix is to reboot the machine.

See tomzx/gkm-java/issues/1.

Does not work on linux

OS: raspbian (on raspberry pi 3 model b+)
java -version:

java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode)

javac -version: javac 1.8.0_65

command: java -jar gkm.jar

error:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x643640a4, pid=1116, tid=1982747760
#
# JRE version: Java(TM) SE Runtime Environment (8.0_65-b17) (build 1.8.0_65-b17)
# Java VM: Java HotSpot(TM) Client VM (25.65-b01 mixed mode linux-arm )
# Problematic frame:
# C  [libX11.so.6+0x870a4]  XkbGetUpdatedMap+0x4
#
# Core dump written. Default location: /home/pi/Desktop/startup/node_modules/gkm/lib/core or core.1116
#
# An error report file with more information is saved as:
# /home/pi/Desktop/startup/node_modules/gkm/lib/hs_err_pid1116.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Aborted (core dumped)

key.typed event returns [ 'Undefined' ]

I have tested simple code:
require("gkm").events.on("key.typed",console.log);
Output:

[ 'Undefined' ]
[ 'Undefined' ]
[ 'Undefined' ]

Node version: v8.6.0
NPM version: v5.3.0
java version: 1.8.0_91
javac version: 1.8.0_60
OS: Windows 7 (x64)

not working with Electron-packager

Hi there.
Was testing stuff out while making an app and noticed that events are not fired after the application was packaged.
Tested this with simple

gkm.events.on('key.*', function(data) {
  console.log(data[0]);
});

and while unpackaged it works, after electron-packager it stops triggering all possible events.

Distribution with Electron

When I package up the application, if the user doesn't have Java installed gkm won't run.

I've run into the same issue with gm and have packaged a binary with Electron to distribute. I can then use their appPath option to refer to the local gm instead of looking for a globally installed gm.

Here's the easiest place to check that out:
https://github.com/aheckmann/gm/blob/c1bef9d4fd21e34ef8138f44a85c342aeae1f174/lib/compare.js#L24

I was going to do the changes myself and create a pull request but I think it'll end up needing to change the way people need to implement gkm in their project. What are your thoughts on this change?

JNativeHook.jar does not work with jdk15.0.2 64-bit (workaround available)

I recently updated to jdk15.0.2 and realized that gmk stopped working for me. I did however find a workaround for this issue:

  1. Download jnativehook-2.1.0.zip
  2. Open jnativehook-2.1.0.zip and navigate to jnativehook\jar\jnativehook-2.1.0.jar
  3. Extract jnativehook-2.1.0.jar to <project-path>\node_modules\gkm\lib\lib\
  4. Delete file JNativeHook.jar in <project-path>\node_modules\gkm\lib\lib\
  5. Re-name jnativehook-2.1.0.jar to JNativeHook.jar

I have yet to test this method with earlier versions of java.

Allow consuming events

JNativeHook has added the ability to attempt to consume native events, see docs page here.

This feature is currently listed as unsupported by the devs, because it doesn't work on some unix platforms, not sure if this library is designed to be crossplatform or not, but the ability to consume events would be very nice.

EventEmitter2 is not a constructor

Framework: electron
OS: MAC catalina 10.15.6
Package.json
"eventemitter2": "^6.4.4",
"gkm": "^0.2.0",
Error
TypeError: EventEmitter2 is not a constructor
at eval (webpack:///./node_modules/gkm/gkm.js?:9:14)
at Object../node_modules/gkm/gkm.js (/Users////dist_electron/index.js:1622:1)
at webpack_require (/Users/
//team-viewer/dist_electron/index.js:20:30)
at eval (webpack:///./src/background.js?:15:13)
at Module../src/background.js (/Users/
///dist_electron/index.js:3802:1)
at webpack_require (/Users/
///dist_electron/index.js:20:30)
at eval (webpack:///multi_./src/background.js?:1:18)
at Object.0 (/Users/
///dist_electron/index.js:3813:1)
at webpack_require (/Users/
///dist_electron/index.js:20:30)
at /Users/
//*/dist_electron/index.js:84:18

How to delete listeners?

Is it possible to add a hook to remove all listeners?
It's quite useful in event handler:

process.on('exit'....

`key.released` event doesn't always seem to fire when a key is released

This makes it look like certain keys are stuck and are always pressed.

This is especially bad if I want to respond to a key-combination like Alt+F1.

I can likely create a small repro case if this is not a known issue and is doubted, just let me know.

I also realized just now that maybe I can also create some kind of an abstraction to hide this issue, because genuine stuck/pressed keys repeatedly fire new key.pressed events, so if for about a second I don't get any of those, I can safely assume that its due to this bug and the key is in fact not pressed.

This can work, though of course it would be preferable that this is fixed somewhere upstream because this would introduce a noticeable lag on occasion when responding to a user releasing a key.


Somewhat off-topic, but I am also baffled by the lack of available and reliable global keyboard hooks for node.js. For a while I was using iohook, until I realised that it doesn't at all work when two apps require it at once. It makes Windows OS freeze. That's a pretty big deal-breaker.

Now, gkm, this package, seems to work much better, but like I say above, it's not fully reliable. And it also seems to not be actively maintained? And yeah, maybe I can smooth out these rough edges and live with this, but I am perplexed as to what people actually use if/when they want to respond in Node to a global keyboard shortcut. Do people just never want to do that? Do they use something I am not aware of?

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.