Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "GetPID.h"
  2.  
  3. @implementation SpotifyRemoteAppDelegate
  4.  
  5. @synthesize window;
  6.  
  7. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  8.  
  9.     NSLog(@"Sleeping");
  10.     NSLog(@"Spotify PID: %d", GetPIDForProcessName("Spotify"));
  11.     sleep(10);
  12.    
  13.     [self pressNextButton];
  14. }
  15.  
  16. - (void)pressNextButton {
  17.  
  18.     NSLog(@"Pressing button");
  19.    
  20.     ProcessSerialNumber psn;
  21.     //GetFrontProcess(&psn);
  22.     GetProcessForPID(GetPIDForProcessName("Spotify"), &psn); //GetPIDForProcessName is not interesting. it just returns PID of the program name supplied
  23.    
  24.     CGEventRef leftDown;
  25.     leftDown = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)123, TRUE)// Right arrow down
  26.     CGEventSetFlags(leftDown, kCGEventFlagMaskCommand); // apply the command modifier key
  27.    
  28.     CGEventRef leftUp;
  29.     leftUp = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)123, FALSE);       // Right arrow up
  30.    
  31.  
  32.    
  33.     CGEventPostToPSN(&psn, leftDown);
  34.    
  35.     CGEventPostToPSN(&psn, leftUp);
  36.    
  37.     CFRelease(leftUp);
  38.     CFRelease(leftDown);
  39.  
  40.     NSLog(@"Pressed!!");
  41.    
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement