Now CGEventCreateKeyboardEvent just doesn't work...
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