Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "GetPID.h"
- @implementation SpotifyRemoteAppDelegate
- @synthesize window;
- - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
- NSLog(@"Sleeping");
- NSLog(@"Spotify PID: %d", GetPIDForProcessName("Spotify"));
- sleep(10);
- [self pressNextButton];
- }
- - (void)pressNextButton {
- NSLog(@"Pressing button");
- ProcessSerialNumber psn;
- //GetFrontProcess(&psn);
- GetProcessForPID(GetPIDForProcessName("Spotify"), &psn); //GetPIDForProcessName is not interesting. it just returns PID of the program name supplied
- CGEventRef leftDown;
- leftDown = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)123, TRUE); // Right arrow down
- CGEventSetFlags(leftDown, kCGEventFlagMaskCommand); // apply the command modifier key
- CGEventRef leftUp;
- leftUp = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)123, FALSE); // Right arrow up
- CGEventPostToPSN(&psn, leftDown);
- CGEventPostToPSN(&psn, leftUp);
- CFRelease(leftUp);
- CFRelease(leftDown);
- NSLog(@"Pressed!!");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement