Open jasonswearingen opened 9 years ago
can use this for the low-level capture: http://nodejs.org/api/tty.html#tty_rs_setrawmode_mode
I'm not sure I understand how this would be of any use in node. It is a server side language so there is no concept of keyboard shortcuts. Could you clarify?
NW.js (node-webkit) allows using nodejs to make desktop applications,
but even without that, if you are making a server app that is interactive (example: utils)
lots of people (such as myself) use nodejs as a general-purpose application platform
Thanks @jasonswearingen. What exactly do I need to do to support this?
I added module.exports support here 7f453869d29871ede7c8aa6f345c361c53d317b7
I also added the ability to specify what element to have mousetrap bind to in version 1.5. I would imagine it should work in the latest version?
Mousetrap works fine on Node Webkit (nwjs) version 9.2, 11.5 and 12 (I'm saying those because I haven't tried any other nwjs version). We use it for all keyboard interaction in Popcorn Time.
We import it through bower though, not npm.
Content of bower.json
:
{
"name": "popcorn-time",
"dependencies": {
"mousetrap": "~1.4.6"
},
"dependenciesIgnore": {
"mousetrap": ["tests", ".gitignore", "./*!mousetrap.min.js"],
}
}
Content of app.js
:
Mousetrap.bind(['shift+f12', 'f12', 'command+0'], function (e) {
win.showDevTools();
});
I use "bare" nodejs to write console apps and it would be very nice to use mousetrap.
But if it's difficult to figure out, I am OK with being required to take a dependency on a bigger framework like nw.js
oh sorry I confused nodejs and nwjs x)
@jasonswearingen how did you manage for /plugins
or did you not use any?
if you want load mousetrap from node web-kit context few changes are required:
if(typeof document == "undefined"){
document = window.document;
}
if(typeof navigator == "undefined"){
navigator = window.navigator;
}
}) (window, document); - > }) (window);
keys = keys instanceof Array ? keys : [keys];
should be :
keys = Array.isArray(keys) ? keys : [keys];
https://github.com/nwjs/nw.js/wiki/Differences-of-JavaScript-contexts#working-around-differences-of-contexts@dafik thanks for your comment here. I just pushed an update in 1.6.0 to make it “play nicer” with server side environments, but I don't think it will help anything with regards to this issue.
Is there a way to make both cases work that can be done directly in mousetrap? The isArray
thing is simple enough and there is an existing PR open for that, but I'm not sure the best way to handle document. Should I assume that if window
is defined and document/navigator
are not, but they are defined on window that I should use the ones on window? That seems awfully fragile/hacky.
any chance nodejs could be supported in the near future?