-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmac-keyboard.js
50 lines (39 loc) · 977 Bytes
/
mac-keyboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Node mac-keyboard. by Jesus García
* ----------------------------------------------------------------
*
* @link http://www.ctwhome.com/leaplearn
* @copyright 2014 Jesus García
* @date 26/09/14, 11:25.
*
* SERVER NODE.JS
* ---------------------
* Node module to fire keyboard events from a node server.
* using NodObjC (https://github.com/TooTallNate/NodObjC).
*/
'use strict'
var $ = require('nodobjc');
$.framework('Cocoa');
var pool;
var init = function() {
pool = $.NSAutoreleasePool('alloc')('init');
}
var pressKey = function(key){
// Key to press
key = key || 125;
// Keyboard key event
var keyEvent = $.CGEventCreateKeyboardEvent(null, key, true);
// Fire event
$.CGEventPost($.kCGHIDEventTap, keyEvent);
console.log("Key fired: ", key);
}
//*********
var quit = function() {
pool('drain');
}
// Make visible the funcitons
module.exports = {
init: init,
pressKey: pressKey,
quit: quit
}