Comments (35)
Hello guys. I just implement libuiohook for node.js.
Now we can hook all keyboard and mouse events globally.
This module also support electron and nw.js
https://www.npmjs.com/package/iohook
PS. It is cross platform module already tested in Mac and Ubuntu. Should good work in windows and other systems, what supported from libuiohook
from robotjs.
I generally use nw.js for hotkeys but as you mentioned its lacking. I'm hoping they improve that because I don't think I want to include hotkey support in RobotJS. If I do work on it, it will be a separate module. I think I'm going to do the same for window management.
from robotjs.
I ran into a block with the c++ EventEmitter. I'm going to rewrite the library with a getKeyState type function. Then I'll figure out the events.
from robotjs.
@Thr1ve I haven't seen a node module, but there is libuiohook , which could probably be wrapped with nan (or something), similar to how robotjs itself is designed.
from robotjs.
+1. Built-in text expansion capabilities similar to AutoHotkey would be a massive benefit.
from robotjs.
@Thr1ve but RobotJS can get the mouse position currently.
from robotjs.
@fohara thanks for the link! I'll try this library and if it works well, I'll turn it into a node module. It would be very easy.
from robotjs.
@octalmage excellent. I was able to compile and run the demohook
example (./configure --enable-demo
) from the repo on OS X and it seemed to work well.
from robotjs.
Awesome! Can't wait to try it out.
from robotjs.
@octalmage Completely agree on the separate module thing; sorry if I implied otherwise! In my mind, there would be a really simple, small, and separate module that would solely listen for any keyboard / mouse events and then emit them as a events / streams / observables / whatever.
Second, there would be a layer ( also separate from robotjs; totally with you re: keeping hotkeys separate ) that could recognize key combinations / sequences and send the appropriate commands to robotjs. I would think we could easily bend/hack something like Mousetrap to work for this?
@fohara Thanks! Can't say I know how to make that work, but it looks like a good time to learn!
I've been dreaming of a javascript version of AutoHotkey for so long... major props to @octalmage for what he's done so far 👍
from robotjs.
Gotcha! I for sure will to try to replace each AHK feature with Node.js modules. If libuiohook works out we'll have a great start for key listening. I'll keep y'all updated!
from robotjs.
@fohara did you encounter this error?
hook_run [882]: Accessibility API is disabled!
Failed to enable access for assistive devices.
I tried adding it to the list of allowed accessibility apps, but that isn't helping.
from robotjs.
@octalmage ah yes, I did encounter that accessibility error. My short term solution was to add iTerm (or any terminal app) to the allowed list. There is probably a more intuitive way of granting permission for this, but I haven't looked into it yet.
from robotjs.
Ah gotcha. This system is so silly. I had to remove and re-add iterm2.
from robotjs.
@octalmage yeah, there must be a programmatic way to handle this. I remember seeing this before, I think with Sikuli perhaps. There was some flag that prompted permission for accessibility, I'll see if I can find it.
from robotjs.
This tool does it, we can look at the code:
https://github.com/jacobsalmela/tccutil
But yeah, libuiohook is so perfect. Just need to create an EventEmitter in V8 and we'll be good to go. Looking into this now.
from robotjs.
It looks like emitting events isn't very straight forward but I figured it out. Woohoo!
from robotjs.
@octalmage nice! Looking forward to seeing how the event emitting works for this.
from robotjs.
So I've made good progress on this, but the library outputs the copyright when it's included:
Do you think I should contact the author to see if it's ok to remove it? Or just remove it? I don't want to release the project with this copyright notice, it's ugly.
from robotjs.
@octalmage good news on the progress! Regarding the copyright notice, you should be able to suppress it by building the lib with the --enable-quiet
config, if I'm understanding this correctly.
from robotjs.
@fohara oh duh, thanks!
from robotjs.
Any updates on this @octalmage?
from robotjs.
This isn't a priority at the moment, I wouldn't expect it anytime soon. Sorry!
from robotjs.
Looking for a replacement for AutoHotkey, and this is saddening... : (
-
For now, I think I'm going to try using edge.js (http://tjanczuk.github.io/edge)) to embed C# code, which'll hook into the windows dll's for keyboard input, and trigger nodejs callbacks when they're pressed. (This should also be nice in case I want to migrate over more os-involved operations from my autohotkey scripts, like window manipulation)
-
If that doesn't work/is too difficult, I'll see if I can use node-ffi (https://github.com/node-ffi/node-ffi) to interface with the windows dll's directly.
-
If that doesn't work, I'll probably just use the input listener system that's already being used for this other nodejs automation repo: https://github.com/relipse/JsRoboKey
(Actually, I might just try using #3 to begin with; depends mostly on whether I can find some easy C# code to capture global hotkeys and send them back to nodejs.)
Anyway, I'll post back here with my results! (Since this is a pretty significant feature for an automation system)
P.S. I realize the approaches above (#1 and #2 anyway) would be Windows-only solutions, so would probably not be wanted as a part/listed-dependency for this project. And that you already have something of a solution using nw.js. But I figured it'd be helpful to at least provide one path of adding hotkeys for other Windows users browsing these threads and not seeing a way explained yet. (I looked briefly at the nw.js project, and didn't see the way you captured hotkeys using it)
from robotjs.
Check out:
https://github.com/electron/electron/blob/master/docs/api/global-shortcut.md
https://github.com/nwjs/nw.js/wiki/shortcut
I use both of these in different apps and they work great for my purpose!
from robotjs.
Thanks for making the iohook library WilixLead!
Unfortunately, I'm getting an error trying to use it: wilix-team/iohook#16
from robotjs.
I also tried this very similar package: https://github.com/ayoubserti/node-iohook
But it also had an error, while installing. In that case, it's because I didn't have the Visual C++ Build Tools installed. I didn't feel like restarting, and installing the build tools, to try the module out. (at least while other options existed)
Which brings me to my third attempt: https://github.com/tomzx/gkm
This one finally works! However, it's not preferred, since it uses Java; but for Windows users, it's probably the easiest option atm. (at least, if you can't get the iohook or node-iohook libraries working)
from robotjs.
It would be nice to have a Wiki page listing various libraries that work well with robotjs, for achieving various automation functions.
If it's okay with @octalmage, I've gone ahead and created the page here: https://github.com/octalmage/robotjs/wiki/Plugins-(or-compatible-modules)
I plan to create some modules myself later, as I'd like to eventually replace AutoHotkey entirely. (AutoHotkey is nice, but it's scripting language is terrible)
from robotjs.
Venryx,
This is also a goal of mine. Love what AHK can do, but hate AHK's language. Plus version 2 has been in development for 6+ years. And even if/when that is released, it does not really fix the language issues, but mostly remove the horrible Command syntax in favor of function() syntax.
I have wanted to use JS for years to replace my product which is written in AHK. I plan to use NodeJS, TypeScript, Electron and Aurelia, but since I have a full-time job this conversion goes very slowly. I would really enjoying partnering with anyone here on replacing AHK with a cross-platform equivalent.
If interested, please contact me directly at [email protected].
from robotjs.
Hi mviens.
I have the same goal, however I've come to believe it's best to build such a system incrementally, based on the foundation here in robotjs. This is because robotjs already has a userbase, and the language/build-process is good, so we can just build up modules around it.
For example, I plan to make a module which creates a system-icon at the bottom-right of screen, from which the user can start, stop, or edit a given script file.
I plan to make another which adds the ability to query, move, and otherwise control various windows. So for example, an easy way to check the title of the active window, minimize it, etc.
We could build a new system from the ground up, but because the NodeJS module system is so flexible (and because gaining traction for a new software system is so hard), I think it's best to just build on this project here (robotjs) and transform it into the full-fledged software we want.
By the way, node-ffi is very convenient for hooking into native dll functions. You can do so entirely in JS land! (Even callbacks; I've used it to implement a full-fledged JS keyboard hook, which I now use everyday for global hotkeys. An old capture: https://github.com/Venryx/vdm-window-manager/blob/333f7d1284fbfbea92e4903b4a5a50ebbab685ea/Source/Input/HotkeyManager.ts)
from robotjs.
What does this project (https://github.com/octalmage/robotjs) plan on doing differently than the already built/working project (https://github.com/robot/robot-js)? It seems like the other project has not been updated in a while, does appears to be well thought out and capable.
from robotjs.
Use RobotJS to troubleshoot Electron's GlobalShortcut.
Use shortcuts for numerals (0-9) but as keys not issued plus values when pressed.
A solution to instantiate the keyTap shortly after an event capture:
globalShortcut.register ('6', () => { that.logger = "" + that.logger + 6 robot.keyTap ("numpad_6"); })
So a solution to use as a Global Shortcut! :)
from robotjs.
This issue has been closed because it has been inactive for > 180 days.
You may reopen this issue if it has been closed in error.
from robotjs.
For anyone looking for AutoHotkey-like expansion, I've found Espanso to be a good replacement.
from robotjs.
any updates?
from robotjs.
Related Issues (20)
- install robotjs is confused, why not provider package like nutjs HOT 2
- Mouse pointer doesn't work in locked screen of MacOS while using screen share app
- [Bug]: Fatal error in V8: v8 ArrayBuffer NewBackingStore When the V8 Sandbox is enabled, ArrayBuffer backing stores must be allocated inside the sandbox address space. Please use an appropriate ArrayBuffer::Allocator to allocate these buffers, or disable the sandbox. HOT 1
- Multiple compile warnings and an error in 0.6.0 with node 16.14.2 - error in mouse.c HOT 3
- How to stop moveMouseSmooth?
- i hope one day u implement Image search HOT 1
- Returned image buffer has Red and Blue channels swapped [b, g, r, a] HOT 1
- mouseMove 960, 540 does not move to center of screen 1920x1080 HOT 2
- How to make screen of visible window on macos? HOT 2
- git clone npm i why error HOT 2
- All key events continuously hold down keys on Windows only. HOT 1
- Does not work on windows 11 HOT 1
- Using the typeString() method does not let you find the name of a file.
- Installing for nw.js - "A dynamic link library (DLL) initialization routine failed."
- Robotjs doesn't work with Electron, current time 2023.11.27 HOT 3
- or
- In the multi-instance tool, RobotJS is not working. There are no issues with reading properties, but moving the mouse or pressing the keyboard is not functioning correctly.
- Is there anyway to use this library in Nextjs app
- I cannot install robotjs HOT 7
- UTF-8 client type string HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from robotjs.