Skip to content

Instantly share code, notes, and snippets.

@radj
Created May 21, 2015 07:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save radj/a3d70ceb36be6d3ab61e to your computer and use it in GitHub Desktop.
Save radj/a3d70ceb36be6d3ab61e to your computer and use it in GitHub Desktop.
#include <substrate.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <IOKit/hid/IOHIDEventTypes.h>
#include <IOKit/hidsystem/IOHIDUsageTables.h>
#include <GraphicsServices/GraphicsServices.h>
typedef CFTypeRef IOHIDEventRef;
typedef CFTypeRef IOHIDEventSystemClientRef;
typedef CFTypeRef IOHIDEventSystemConnectionRef;
MSClassHook(BKAccessibility)
@interface BKHIDClientConnectionManager : NSObject
- (IOHIDEventSystemConnectionRef) clientForTaskPort:(mach_port_t)port;
@end
@interface BKAccessibility : NSObject
+ (BKHIDClientConnectionManager *) _eventRoutingClientConnectionManager;
@end
extern "C" {
IOHIDEventRef IOHIDEventCreateKeyboardEvent(CFAllocatorRef allocator, uint64_t time, uint16_t page, uint16_t usage, Boolean down, IOHIDEventOptionBits flags);
IOHIDEventRef IOHIDEventCreateDigitizerEvent(CFAllocatorRef allocator, uint64_t timeStamp, IOHIDDigitizerTransducerType type, uint32_t index, uint32_t identity, uint32_t eventMask, uint32_t buttonMask, IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOHIDFloat tipPressure, IOHIDFloat barrelPressure, Boolean range, Boolean touch, IOOptionBits options);
IOHIDEventRef IOHIDEventCreateDigitizerFingerEvent(CFAllocatorRef allocator, uint64_t timeStamp, uint32_t index, uint32_t identity, uint32_t eventMask, IOHIDFloat x, IOHIDFloat y, IOHIDFloat z, IOHIDFloat tipPressure, IOHIDFloat twist, Boolean range, Boolean touch, IOOptionBits options);
IOHIDEventSystemClientRef IOHIDEventSystemClientCreate(CFAllocatorRef allocator);
void IOHIDEventAppendEvent(IOHIDEventRef parent, IOHIDEventRef child);
void IOHIDEventSetIntegerValue(IOHIDEventRef event, IOHIDEventField field, int value);
void IOHIDEventSetSenderID(IOHIDEventRef event, uint64_t sender);
void IOHIDEventSystemClientDispatchEvent(IOHIDEventSystemClientRef client, IOHIDEventRef event);
void IOHIDEventSystemConnectionDispatchEvent(IOHIDEventSystemConnectionRef connection, IOHIDEventRef event);
}
static void SimulatePowerBtn()
{
Log("send Pwr btn down");
VNCSendHIDEvent(IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault,
mach_absolute_time(),
kHIDPage_Consumer,
kHIDUsage_Csmr_Power,
1, 0));
usleep(50000);
Log("send Pwr btn up");
VNCSendHIDEvent(IOHIDEventCreateKeyboardEvent(kCFAllocatorDefault,
mach_absolute_time(),
kHIDPage_Consumer,
kHIDUsage_Csmr_Power,
0, 0));
}
int main(int argc, char **argv, char **envp)
{
// Send power button
SimulatePowerBtn();
sleep(1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment