- (void)trigger {
CGFloat height = NSScreen.mainScreen.frame.size.height;
NSPoint mouseLoc = NSEvent.mouseLocation;
- CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseDown : kCGEventRightMouseDown;
+ CGEventType eventType = _button == kCGMouseButtonLeft ? kCGEventLeftMouseDown
+ : _button == kCGMouseButtonRight ? kCGEventRightMouseDown
+ : kCGEventOtherMouseDown;
CGEventRef click = CGEventCreateMouseEvent(NULL,
eventType,
CGPointMake(mouseLoc.x, height - mouseLoc.y),
_button);
if (clickCount >= 3 || [upTime compare:[NSDate date]] == NSOrderedAscending
- || !CGPointEqualToPoint(NSEvent.mouseLocation, clickPosition))
+ || !CGPointEqualToPoint(mouseLoc, clickPosition))
clickCount = 1;
else
++clickCount;
CGEventSetIntegerValueField(click, kCGMouseEventClickState, clickCount);
-
CGEventPost(kCGHIDEventTap, click);
CFRelease(click);
+ clickPosition = mouseLoc;
}
- (void)untrigger {
upTime = [NJOutputMouseButton dateWithClickInterval];
- clickPosition = NSEvent.mouseLocation;
+ NSPoint mouseLoc = NSEvent.mouseLocation;
CGFloat height = NSScreen.mainScreen.frame.size.height;
- CGEventType eventType = (_button == kCGMouseButtonLeft) ? kCGEventLeftMouseUp : kCGEventRightMouseUp;
+ CGEventType eventType = _button == kCGMouseButtonLeft ? kCGEventLeftMouseUp
+ : _button == kCGMouseButtonRight ? kCGEventRightMouseUp
+ : kCGEventOtherMouseUp;
CGEventRef click = CGEventCreateMouseEvent(NULL,
eventType,
- CGPointMake(clickPosition.x, height - clickPosition.y),
+ CGPointMake(mouseLoc.x, height - mouseLoc.y),
_button);
CGEventSetIntegerValueField(click, kCGMouseEventClickState, clickCount);
CGEventPost(kCGHIDEventTap, click);
CFRelease(click);
}
+- (int)humanIndexedButton {
+ switch (_button) {
+ case kCGMouseButtonLeft: return 0;
+ case kCGMouseButtonCenter: return 1;
+ case kCGMouseButtonRight: return 2;
+ default: return 0;
+ }
+}
+
+- (void)setHumanIndexedButton:(int)humanIndexedButton {
+ switch (humanIndexedButton) {
+ case 0: _button = kCGMouseButtonLeft; break;
+ case 1: _button = kCGMouseButtonCenter; break;
+ case 2: _button = kCGMouseButtonRight; break;
+ default: _button = kCGMouseButtonLeft;
+ }
+}
+
@end
output.axis = [serialization[@"axis"] intValue];
output.speed = [serialization[@"speed"] floatValue];
if (!output.speed)
- output.speed = 4;
+ output.speed = 10;
return output;
}
return YES;
}
+#define CLAMP(a, l, h) MIN(h, MAX(a, l))
+
- (BOOL)update:(NJDeviceController *)jc {
if (self.magnitude < 0.05)
return NO; // dead zone
- CGFloat height = NSScreen.mainScreen.frame.size.height;
+ CGSize size = NSScreen.mainScreen.frame.size;
- float dx = 0.f, dy = 0.f;
+ CGFloat dx = 0, dy = 0;
switch (_axis) {
case 0:
dx = -self.magnitude * _speed;
break;
}
NSPoint mouseLoc = jc.mouseLoc;
- mouseLoc.x += dx;
- mouseLoc.y -= dy;
+ mouseLoc.x = CLAMP(mouseLoc.x + dx, 0, size.width - 1);
+ mouseLoc.y = CLAMP(mouseLoc.y - dy, 0, size.height - 1);
jc.mouseLoc = mouseLoc;
CGEventRef move = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved,
- CGPointMake(mouseLoc.x, height - mouseLoc.y),
+ CGPointMake(mouseLoc.x, size.height - mouseLoc.y),
0);
- CGEventSetType(move, kCGEventMouseMoved);
CGEventSetIntegerValueField(move, kCGMouseEventDeltaX, (int)dx);
CGEventSetIntegerValueField(move, kCGMouseEventDeltaY, (int)dy);
CGEventPost(kCGHIDEventTap, move);
+
+ if (CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonLeft)) {
+ CGEventSetType(move, kCGEventLeftMouseDragged);
+ CGEventSetIntegerValueField(move, kCGMouseEventButtonNumber, kCGMouseButtonLeft);
+ CGEventPost(kCGHIDEventTap, move);
+ }
+ if (CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonRight)) {
+ CGEventSetType(move, kCGEventRightMouseDragged);
+ CGEventSetIntegerValueField(move, kCGMouseEventButtonNumber, kCGMouseButtonRight);
+ CGEventPost(kCGHIDEventTap, move);
+ }
+ if (CGEventSourceButtonState(kCGEventSourceStateHIDSystemState, kCGMouseButtonCenter)) {
+ CGEventSetType(move, kCGEventOtherMouseDragged);
+ CGEventSetIntegerValueField(move, kCGMouseEventButtonNumber, kCGMouseButtonCenter);
+ CGEventPost(kCGHIDEventTap, move);
+ }
+
CFRelease(move);
return YES;
}
<reference key="NSNextResponder" ref="177223957"/>
<int key="NSvFlags">285</int>
<array class="NSMutableArray" key="NSSubviews">
- <object class="NSSlider" id="792189805">
- <reference key="NSNextResponder" ref="471332453"/>
- <int key="NSvFlags">265</int>
- <string key="NSFrame">{{191, 24}, {130, 12}}</string>
- <reference key="NSSuperview" ref="471332453"/>
- <reference key="NSWindow"/>
- <reference key="NSNextKeyView"/>
- <string key="NSReuseIdentifierKey">_NS:9</string>
- <bool key="NSEnabled">YES</bool>
- <object class="NSSliderCell" key="NSCell" id="423057230">
- <int key="NSCellFlags">-2080374784</int>
- <int key="NSCellFlags2">262144</int>
- <string key="NSContents"/>
- <string key="NSCellIdentifier">_NS:9</string>
- <reference key="NSControlView" ref="792189805"/>
- <double key="NSMaxValue">30</double>
- <double key="NSMinValue">0.0</double>
- <double key="NSValue">15</double>
- <double key="NSAltIncValue">0.0</double>
- <int key="NSNumberOfTickMarks">0</int>
- <int key="NSTickMarkPosition">1</int>
- <bool key="NSAllowsTickMarkValuesOnly">NO</bool>
- <bool key="NSVertical">NO</bool>
- </object>
- <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
- </object>
- <object class="NSSlider" id="385416822">
- <reference key="NSNextResponder" ref="471332453"/>
- <int key="NSvFlags">265</int>
- <string key="NSFrame">{{191, 108}, {176, 12}}</string>
- <reference key="NSSuperview" ref="471332453"/>
- <reference key="NSWindow"/>
- <reference key="NSNextKeyView" ref="125828224"/>
- <string key="NSReuseIdentifierKey">_NS:9</string>
- <bool key="NSEnabled">YES</bool>
- <object class="NSSliderCell" key="NSCell" id="5417367">
- <int key="NSCellFlags">-2080374784</int>
- <int key="NSCellFlags2">262144</int>
- <string key="NSContents"/>
- <string key="NSCellIdentifier">_NS:9</string>
- <reference key="NSControlView" ref="385416822"/>
- <double key="NSMaxValue">20</double>
- <double key="NSMinValue">0.0</double>
- <double key="NSValue">4</double>
- <double key="NSAltIncValue">0.0</double>
- <int key="NSNumberOfTickMarks">0</int>
- <int key="NSTickMarkPosition">1</int>
- <bool key="NSAllowsTickMarkValuesOnly">NO</bool>
- <bool key="NSVertical">NO</bool>
- </object>
- <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
- </object>
<object class="NSSegmentedControl" id="875916470">
<reference key="NSNextResponder" ref="471332453"/>
<int key="NSvFlags">265</int>
<object class="NSSegmentItem">
<double key="NSSegmentItemWidth">44</double>
<string key="NSSegmentItemLabel">←</string>
- <bool key="NSSegmentItemSelected">YES</bool>
<int key="NSSegmentItemImageScaling">0</int>
</object>
<object class="NSSegmentItem">
<double key="NSSegmentItemWidth">64</double>
<string key="NSSegmentItemLabel">↑</string>
<string key="NSSegmentItemTooltip">Scroll up continuously</string>
- <bool key="NSSegmentItemSelected">YES</bool>
<int key="NSSegmentItemImageScaling">0</int>
</object>
<object class="NSSegmentItem">
</object>
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
</object>
+ <object class="NSSlider" id="792189805">
+ <reference key="NSNextResponder" ref="471332453"/>
+ <int key="NSvFlags">265</int>
+ <string key="NSFrame">{{191, 24}, {130, 16}}</string>
+ <reference key="NSSuperview" ref="471332453"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSSliderCell" key="NSCell" id="423057230">
+ <int key="NSCellFlags">-2080374784</int>
+ <int key="NSCellFlags2">262144</int>
+ <string key="NSContents"/>
+ <string key="NSCellIdentifier">_NS:9</string>
+ <reference key="NSControlView" ref="792189805"/>
+ <double key="NSMaxValue">30</double>
+ <double key="NSMinValue">0.0</double>
+ <double key="NSValue">15</double>
+ <double key="NSAltIncValue">0.0</double>
+ <int key="NSNumberOfTickMarks">11</int>
+ <int key="NSTickMarkPosition">1</int>
+ <bool key="NSAllowsTickMarkValuesOnly">YES</bool>
+ <bool key="NSVertical">NO</bool>
+ </object>
+ <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
+ </object>
<object class="NSSegmentedControl" id="125828224">
<reference key="NSNextResponder" ref="471332453"/>
<int key="NSvFlags">265</int>
<reference key="NSControlView" ref="125828224"/>
<array class="NSMutableArray" key="NSSegmentImages">
<object class="NSSegmentItem">
- <double key="NSSegmentItemWidth">87</double>
+ <double key="NSSegmentItemWidth">55</double>
<string key="NSSegmentItemLabel">Left</string>
- <bool key="NSSegmentItemSelected">YES</bool>
<int key="NSSegmentItemImageScaling">0</int>
</object>
<object class="NSSegmentItem">
- <double key="NSSegmentItemWidth">86</double>
- <string key="NSSegmentItemLabel">Right</string>
+ <string key="NSSegmentItemLabel">Center</string>
<int key="NSSegmentItemTag">1</int>
<int key="NSSegmentItemImageScaling">0</int>
</object>
+ <object class="NSSegmentItem">
+ <double key="NSSegmentItemWidth">55</double>
+ <string key="NSSegmentItemLabel">Right</string>
+ <int key="NSSegmentItemImageScaling">0</int>
+ </object>
</array>
<int key="NSSegmentStyle">1</int>
</object>
<bool key="NSAllowsLogicalLayoutDirection">NO</bool>
</object>
+ <object class="NSSlider" id="385416822">
+ <reference key="NSNextResponder" ref="471332453"/>
+ <int key="NSvFlags">265</int>
+ <string key="NSFrame">{{191, 108}, {176, 16}}</string>
+ <reference key="NSSuperview" ref="471332453"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="125828224"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSSliderCell" key="NSCell" id="5417367">
+ <int key="NSCellFlags">67108864</int>
+ <int key="NSCellFlags2">262144</int>
+ <string key="NSContents"/>
+ <string key="NSCellIdentifier">_NS:9</string>
+ <reference key="NSControlView" ref="385416822"/>
+ <double key="NSMaxValue">20</double>
+ <double key="NSMinValue">0.0</double>
+ <double key="NSValue">10</double>
+ <double key="NSAltIncValue">0.0</double>
+ <int key="NSNumberOfTickMarks">11</int>
+ <int key="NSTickMarkPosition">1</int>
+ <bool key="NSAllowsTickMarkValuesOnly">YES</bool>
+ <bool key="NSVertical">NO</bool>
+ </object>
+ <bool key="NSAllowsLogicalLayoutDirection">NO</bool>
+ </object>
<object class="NSCustomView" id="57697638">
<reference key="NSNextResponder" ref="471332453"/>
<int key="NSvFlags">265</int>
<string key="734.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="735.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="744.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
- <integer value="1" key="745.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
+ <integer value="2" key="745.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
<string key="745.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="749.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
- <integer value="1" key="750.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
+ <integer value="0" key="750.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
<string key="750.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="754.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
- <integer value="1" key="755.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
+ <integer value="0" key="755.IBNSSegmentedControlInspectorSelectedSegmentMetadataKey"/>
<string key="755.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="778.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
<string key="81.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>