-
Notifications
You must be signed in to change notification settings - Fork 20
/
index.js
39 lines (31 loc) · 892 Bytes
/
index.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
var events = require('events')
var bindings = require('bindings')
var Mouse = bindings('addon').Mouse
module.exports = function () {
var that = new events.EventEmitter()
var mouse = null
var left = false
var right = false
that.once('newListener', function () {
mouse = new Mouse(function (type, x, y) {
if (type === 'left-down') left = true
else if (type === 'left-up') left = false
else if (type === 'right-down') right = true
else if (type === 'right-up') right = false
if (type === 'move' && left) type = 'left-drag'
else if (type === 'move' && right) type = 'right-drag'
that.emit(type, x, y)
})
})
that.ref = function () {
if (mouse) mouse.ref()
}
that.unref = function () {
if (mouse) mouse.unref()
}
that.destroy = function () {
if (mouse) mouse.destroy()
mouse = null
}
return that
}