• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Now CGEventCreateKeyboardEvent just doesn't work...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Now CGEventCreateKeyboardEvent just doesn't work...


  • Subject: Now CGEventCreateKeyboardEvent just doesn't work...
  • From: Ondra Cada <email@hidden>
  • Date: Wed, 4 Oct 2006 18:27:48 +0200

Eric,

On 4.10.2006, at 16:37, Eric Schlegel wrote:

The recommended workaround is to call CFRelease(CGEventCreate (NULL)) before calling the other APIs

thanks a lot.

Well... now it does not crash, but it does not seem to do anything else, either. May I please ask for a bit more advice what am I overlooking? I would think the following code should hide iTunes; it does not though -- regardless the value of wait I try:

#import <Foundation/Foundation.h>
#import <unistd.h> // usleep

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// insert code here...
NSLog(@"Hello, Apple World! What's there with them blasted events?!?");
CFRelease(CGEventCreate(NULL));
// find iTunes
ProcessSerialNumber serial;
serial.highLongOfPSN=0;
serial.lowLongOfPSN=kNoProcess;
ProcessInfoRec pinfo;
pinfo.processInfoLength=sizeof(ProcessInfoRec);
pinfo.processName=NULL;
pinfo.processAppSpec=NULL;
pinfo.processLocation=NULL;
BOOL ok=NO;
for (;;) {
if (GetNextProcess(&serial)!=noErr) break; // found nothing
if (GetProcessInformation(&serial,&pinfo)==noErr) // 'hook' is iTunes
if ([(id)UTCreateStringForOSType(pinfo.processSignature) isEqualToString:@"hook"]) {
ok=YES;
break;
}
}
if (ok) { // just hide it, for the moment
unsigned wait=100000;
NSLog(@"allright, sending...");
CGEventPostToPSN(&serial,CGEventCreateKeyboardEvent (NULL, (CGKeyCode)0x37, true)); // command
usleep(wait);
CGEventPostToPSN(&serial,CGEventCreateKeyboardEvent (NULL, (CGKeyCode)0x04, true)); // h
usleep(wait);
CGEventPostToPSN(&serial,CGEventCreateKeyboardEvent (NULL, (CGKeyCode)0x04, false));
usleep(wait);
CGEventPostToPSN(&serial,CGEventCreateKeyboardEvent (NULL, (CGKeyCode)0x37, false));
NSLog(@"sent all");
}
[pool release];
return 0;
}


Thanks a lot in advance,
---
Ondra Čada
OCSoftware:     email@hidden               http://www.ocs.cz
private         email@hidden             http://www.ocs.cz/oc


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Now CGEventCreateKeyboardEvent just doesn't work...
      • From: Gregory Cooksey <email@hidden>
    • Re: Now CGEventCreateKeyboardEvent just doesn't work...
      • From: John Stiles <email@hidden>
References: 
 >CGEventCreateKeyboardEvent just crashes?!? (From: Ondra Cada <email@hidden>)
 >Re: CGEventCreateKeyboardEvent just crashes?!? (From: Eric Schlegel <email@hidden>)

  • Prev by Date: Knowing when a window is being dragged?
  • Next by Date: Re: How do I know when my Core Data app is up and running?
  • Previous by thread: Re: CGEventCreateKeyboardEvent just crashes?!?
  • Next by thread: Re: Now CGEventCreateKeyboardEvent just doesn't work...
  • Index(es):
    • Date
    • Thread