diff --git a/README.md b/README.md index cc27204..bf032ea 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ mouse.on('move', function(x, y) { The program will not terminate as long as a mouse listener is active. To allow the program to exit, either call `mouse.unref` (works as `unref`/`ref` on a TCP server) or `mouse.destroy()`. -The events emitted are: `move`, `left-down`, `left-up`, `left-drag`, `right-up`, `right-down` and `right-drag`. For each event the screen coordinates are passed to the handler function. +The events emitted are: `move`, `left-down`, `left-up`, `left-drag`, `right-up`, `right-down`, `right-drag`, `middle-up`, `middle-down` and `middle-drag`. For each event the screen coordinates are passed to the handler function. # Limitations diff --git a/source/mouse.cc b/source/mouse.cc index d22a64d..d32ce16 100644 --- a/source/mouse.cc +++ b/source/mouse.cc @@ -4,18 +4,25 @@ const char* LEFT_DOWN = "left-down"; const char* LEFT_UP = "left-up"; const char* RIGHT_DOWN = "right-down"; const char* RIGHT_UP = "right-up"; +const char* MIDDLE_DOWN = "middle-down"; +const char* MIDDLE_UP = "middle-up"; const char* MOVE = "move"; const char* LEFT_DRAG = "left-drag"; const char* RIGHT_DRAG = "right-drag"; +const char* MIDDLE_DRAG = "middle-drag"; + bool IsMouseEvent(CGEventType type) { return type == kCGEventLeftMouseDown || type == kCGEventLeftMouseUp || type == kCGEventRightMouseDown || type == kCGEventRightMouseUp || + type == kCGEventOtherMouseDown || + type == kCGEventOtherMouseUp || type == kCGEventMouseMoved || type == kCGEventLeftMouseDragged || - type == kCGEventRightMouseDragged; + type == kCGEventRightMouseDragged || + type == kCGEventOtherMouseDragged; } void RunThread(void* arg) { @@ -102,9 +109,12 @@ void Mouse::Run() { CGEventMaskBit(kCGEventLeftMouseUp) | CGEventMaskBit(kCGEventRightMouseDown) | CGEventMaskBit(kCGEventRightMouseUp) | + CGEventMaskBit(kCGEventOtherMouseDown) | + CGEventMaskBit(kCGEventOtherMouseUp) | CGEventMaskBit(kCGEventMouseMoved) | CGEventMaskBit(kCGEventLeftMouseDragged) | - CGEventMaskBit(kCGEventRightMouseDragged); + CGEventMaskBit(kCGEventRightMouseDragged) | + CGEventMaskBit(kCGEventOtherMouseDragged); CFMachPortRef tap = CGEventTapCreate( kCGHIDEventTap, @@ -189,9 +199,12 @@ void Mouse::HandleSend() { if(e.type == kCGEventLeftMouseUp) name = LEFT_UP; if(e.type == kCGEventRightMouseDown) name = RIGHT_DOWN; if(e.type == kCGEventRightMouseUp) name = RIGHT_UP; + if(e.type == kCGEventOtherMouseDown) name = MIDDLE_DOWN; + if(e.type == kCGEventOtherMouseUp) name = MIDDLE_UP; if(e.type == kCGEventMouseMoved) name = MOVE; if(e.type == kCGEventLeftMouseDragged) name = LEFT_DRAG; if(e.type == kCGEventRightMouseDragged) name = RIGHT_DRAG; + if(e.type == kCGEventOtherMouseDragged) name = MIDDLE_DRAG; Local argv[] = { Nan::New(name).ToLocalChecked(),