// File:
// click.m
//
// Compile with:
// gcc -o click click.m -framework ApplicationServices -framework Foundation
//
// Usage:
// ./click
// At the given coordinates it will click and release.
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "virtual_keycodes.h"
#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>
//gcc -o click click.m -framework ApplicationServices -fwork Foundation
int main(int argc, char *argv[]) {
/*
kCGEventNull
Specifies a null event.
kCGEventLeftMouseDown
Specifies a mouse down event with the left button.
kCGEventLeftMouseUp
Specifies a mouse up event with the left button.
kCGEventRightMouseDown
Specifies a mouse down event with the right button.
kCGEventRightMouseUp
Specifies a mouse up event with the right button.
kCGEventMouseMoved
Specifies a mouse moved event.
kCGEventLeftMouseDragged
Specifies a mouse drag event with the left button down.
kCGEventRightMouseDragged
Specifies a mouse drag event with the right button down.
kCGEventKeyDown
Specifies a key down event.
kCGEventKeyUp
Specifies a key up event.
kCGEventFlagsChanged
Specifies a key changed event for a modifier or status key.
kCGEventScrollWheel
Specifies a scroll wheel moved event.
kCGEventTabletPointer
Specifies a tablet pointer event.
kCGEventTabletProximity
Specifies a tablet proximity event.
kCGEventOtherMouseDown
Specifies a mouse down event with one of buttons 2-31.
kCGEventOtherMouseUp
Specifies a mouse up event with one of buttons 2-31.
kCGEventOtherMouseDragged
Specifies a mouse drag event with one of buttons 2-31 down.
kCGEventTapDisabledByTimeout
Specifies an event indicating the event tap is disabled because of timeout.
kCGEventTapDisabledByUserInput
Specifies an event indicating the event tap is disabled because of user input.
*/
//write W LAZARUS
CGEventFlags flags_shift = kCGEventFlagMaskShift;
CGEventRef ev;
CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateCombinedSessionState);
//press down
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_W, true);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press up
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_W, false);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press down
ev = CGEventCreateKeyboardEvent (source, kVK_Space, true);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press up
ev = CGEventCreateKeyboardEvent (source, kVK_Space, false);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press down
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_L, true);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press up
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_L, false);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press down
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_A, true);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press up
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_A, false);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press down
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_Z, true);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press up
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_Z, false);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press down
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_A, true);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press up
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_A, false);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press down
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_R, true);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press up
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_R, false);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press down
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_U, true);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press up
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_U, false);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press down
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_S, true);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press up
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_S, false);
CGEventSetFlags(ev,flags_shift | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
CFRelease(source);
//mouse move and click example
CGEventRef move1 = CGEventCrea]"]>BlockeduseEvent(
NULL, kCGEventMouseMoved,
CGPointMake(200, 200),
kCGMouseButtonLeft // ignored
);
// Left button down at 250x250
CGEventRef click1_down = CGEventCrea]"]>BlockeduseEvent(
NULL, kCGEventLeftMouseDown,
CGPointMake(250, 250),
kCGMouseButtonLeft
);
// Left button down at 250x250
CGEventRef clickr2_down = CGEventCrea]"]>BlockeduseEvent(
NULL, kCGEventRightMouseDown,
CGPointMake(300, 300),
kCGMouseButtonRight
);
CGEventPost(kCGHIDEventTap, move1);
sleep(1);
CGEventPost(kCGHIDEventTap, click1_down);
sleep(1);
CGEventPost(kCGHIDEventTap, clickr2_down);
sleep(1);
CFRelease(click1_down);
CFRelease(clickr2_down);
CFRelease(move1);
//shift + command + 4
//CGEventFlags flags_shift = kCGEventFlagMaskShift;
CGEventFlags flags_command = kCGEventFlagMaskCommand;
//CGEventRef ev;
//CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateCombinedSessionState);
//press down 4
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_4, true);
CGEventSetFlags(ev,flags_shift | flags_command | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
//press up 4
ev = CGEventCreateKeyboardEvent (source, kVK_ANSI_4, false);
CGEventSetFlags(ev,flags_shift | flags_command | CGEventGetFlags(ev)); //combine flags
CGEventPost(kCGHIDEventTap,ev);
CFRelease(ev);
CFRelease(source);
return 0;
}