|
| 1 | +#ifdef __APPLE__ |
| 2 | + |
| 3 | +#include <iostream> |
| 4 | + |
| 5 | +//quartz CG... stuff |
| 6 | +#include <ApplicationServices/ApplicationServices.h> |
| 7 | + |
| 8 | +//sleep |
| 9 | +#include <unistd.h> |
| 10 | + |
| 11 | +#include "xinputsimulatorimplmacos.h" |
| 12 | +#include "notimplementedexception.h" |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +XInputSimulatorImplMacOs::XInputSimulatorImplMacOs() |
| 17 | +{ |
| 18 | + //this->initCurrentMousePosition(); |
| 19 | + |
| 20 | + this->currentX = 500; |
| 21 | + this->currentY = 500; |
| 22 | +} |
| 23 | + |
| 24 | +//void XInputSimulatorImplMacOs::initMouseEvent(int button) |
| 25 | +//{ |
| 26 | + |
| 27 | +//} |
| 28 | + |
| 29 | +void XInputSimulatorImplMacOs::initCurrentMousePosition() |
| 30 | +{ |
| 31 | + throw NotImplementedException(); |
| 32 | +} |
| 33 | + |
| 34 | +void XInputSimulatorImplMacOs::mouseMoveTo(int x, int y) |
| 35 | +{ |
| 36 | + std::cout << "moveTo mac\n"; |
| 37 | + |
| 38 | + CGEventRef mouseEv = CGEventCreateMouseEvent( |
| 39 | + NULL, kCGEventMouseMoved, |
| 40 | + CGPointMake(x, y), |
| 41 | + kCGMouseButtonLeft); |
| 42 | + |
| 43 | + std::cout << "mv: " << mouseEv << std::endl; |
| 44 | + |
| 45 | + CGEventPost(kCGHIDEventTap, mouseEv); |
| 46 | + |
| 47 | + CFRelease(mouseEv); |
| 48 | + |
| 49 | + this->currentX = x; |
| 50 | + this->currentY = y; |
| 51 | +} |
| 52 | + |
| 53 | +void XInputSimulatorImplMacOs::mouseMoveRelative(int x, int y) |
| 54 | +{ |
| 55 | + std::cout << "moveRelative mac\n"; |
| 56 | + |
| 57 | + int newX = this->currentX + x; |
| 58 | + int newY = this->currentY + y; |
| 59 | + |
| 60 | + std::cout << "newx: " << newX << " newy: " << newY << std::endl; |
| 61 | + |
| 62 | + CGEventRef mouseEv = CGEventCreateMouseEvent( |
| 63 | + NULL, kCGEventMouseMoved, |
| 64 | + CGPointMake(newX, newY), |
| 65 | + kCGMouseButtonLeft); |
| 66 | + |
| 67 | + CGEventPost(kCGHIDEventTap, mouseEv); |
| 68 | + |
| 69 | + CFRelease(mouseEv); |
| 70 | + |
| 71 | + this->currentX = newX; |
| 72 | + this->currentY = newY; |
| 73 | +} |
| 74 | + |
| 75 | +//TODO use the button from parameter list |
| 76 | +void XInputSimulatorImplMacOs::mouseDown(int button) |
| 77 | +{ |
| 78 | + //throw NotImplementedException(); |
| 79 | + |
| 80 | + std::cout << "mouseDown mac\n"; |
| 81 | + |
| 82 | + CGEventRef mouseEv = CGEventCreateMouseEvent( |
| 83 | + NULL, kCGEventLeftMouseDown, |
| 84 | + CGPointMake(this->currentX, this->currentY), |
| 85 | + kCGMouseButtonLeft); // use int buttn from parameter |
| 86 | + |
| 87 | + CGEventPost(kCGHIDEventTap, mouseEv); |
| 88 | + |
| 89 | + CFRelease(mouseEv); |
| 90 | + |
| 91 | +} |
| 92 | + |
| 93 | +//TODO use the button from parameter list |
| 94 | +void XInputSimulatorImplMacOs::mouseUp(int button) |
| 95 | +{ |
| 96 | + //throw NotImplementedException(); |
| 97 | + |
| 98 | + std::cout << "mouseDown mac\n"; |
| 99 | + |
| 100 | + CGEventRef mouseEv = CGEventCreateMouseEvent( |
| 101 | + NULL, kCGEventLeftMouseUp, |
| 102 | + CGPointMake(this->currentX, this->currentY), |
| 103 | + kCGMouseButtonLeft); // use int buttn from parameter |
| 104 | + |
| 105 | + CGEventPost(kCGHIDEventTap, mouseEv); |
| 106 | + |
| 107 | + CFRelease(mouseEv); |
| 108 | +} |
| 109 | + |
| 110 | +void XInputSimulatorImplMacOs::mouseClick(int button) |
| 111 | +{ |
| 112 | + //throw NotImplementedException(); |
| 113 | + this->mouseDown(button); |
| 114 | + this->mouseUp(button); |
| 115 | +} |
| 116 | +//kajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjfkajsdölfkjasdölfkjasldökfjaölsdkjfalsdkjfalskdjfaldskjf |
| 117 | +void XInputSimulatorImplMacOs::mouseScrollX(int length) |
| 118 | +{ |
| 119 | + //throw NotImplementedException(); |
| 120 | + |
| 121 | + std::cout << "scroll x mac " << length << std::endl; |
| 122 | + |
| 123 | + int scrollDirection = -1; // 1 left -1 right |
| 124 | + |
| 125 | + if(length < 0){ |
| 126 | + length *= -1; |
| 127 | + scrollDirection *= -1; |
| 128 | + } |
| 129 | + |
| 130 | + //length *= 100; |
| 131 | + |
| 132 | + for(int cnt = 0; cnt < length; cnt++){ |
| 133 | + |
| 134 | + std::cout << "scroll y mac" << std::endl; |
| 135 | + |
| 136 | + CGEventRef scrollEv = CGEventCreateScrollWheelEvent ( |
| 137 | + NULL, kCGScrollEventUnitLine, // kCGScrollEventUnitLine //kCGScrollEventUnitPixel |
| 138 | + 2, //CGWheelCount 1 = y 2 = xy 3 = xyz |
| 139 | + 0, |
| 140 | + scrollDirection); // length of scroll from -10 to 10 higher values lead to undef behaviour |
| 141 | + |
| 142 | + CGEventPost(kCGHIDEventTap, scrollEv); |
| 143 | + |
| 144 | + CFRelease(scrollEv); |
| 145 | + //sleep(1); |
| 146 | + } |
| 147 | +} |
| 148 | + |
| 149 | +void XInputSimulatorImplMacOs::mouseScrollY(int length) |
| 150 | +{ |
| 151 | + //throw NotImplementedException(); |
| 152 | + |
| 153 | + std::cout << "scroll y mac " << length << std::endl; |
| 154 | + |
| 155 | + int scrollDirection = -1; // 1 down -1 up |
| 156 | + |
| 157 | + if(length < 0){ |
| 158 | + length *= -1; |
| 159 | + scrollDirection *= -1; |
| 160 | + } |
| 161 | + |
| 162 | + //length *= 100; |
| 163 | + |
| 164 | + for(int cnt = 0; cnt < length; cnt++){ |
| 165 | + |
| 166 | + std::cout << "scroll y mac" << std::endl; |
| 167 | + |
| 168 | + CGEventRef scrollEv = CGEventCreateScrollWheelEvent ( |
| 169 | + NULL, kCGScrollEventUnitLine, // kCGScrollEventUnitLine //kCGScrollEventUnitPixel |
| 170 | + 1, //CGWheelCount 1 = y 2 = xy 3 = xyz |
| 171 | + scrollDirection); // length of scroll from -10 to 10 higher values lead to undef behaviour |
| 172 | + |
| 173 | + CGEventPost(kCGHIDEventTap, scrollEv); |
| 174 | + |
| 175 | + CFRelease(scrollEv); |
| 176 | + //sleep(1); |
| 177 | + } |
| 178 | +} |
| 179 | + |
| 180 | +void XInputSimulatorImplMacOs::keyDown(int key) |
| 181 | +{ |
| 182 | + throw NotImplementedException(); |
| 183 | +} |
| 184 | + |
| 185 | +void XInputSimulatorImplMacOs::keyUp(int key) |
| 186 | +{ |
| 187 | + throw NotImplementedException(); |
| 188 | +} |
| 189 | + |
| 190 | +#endif //apple |
0 commit comments