• 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
Re: Now CGEventCreateKeyboardEvent just doesn't work...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Now CGEventCreateKeyboardEvent just doesn't work...


  • Subject: Re: Now CGEventCreateKeyboardEvent just doesn't work...
  • From: John Stiles <email@hidden>
  • Date: Wed, 4 Oct 2006 09:50:35 -0700

Ondra, there's a better way.
http://developer.apple.com/documentation/Carbon/Reference/ Process_Manager/Reference/reference.html#//apple_ref/c/func/ ShowHideProcess



On Oct 4, 2006, at 9:27 AM, Ondra Cada wrote:

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:
40blizzard.com


This email sent to email@hidden

_______________________________________________ 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: Ondra Cada <email@hidden>
References: 
 >CGEventCreateKeyboardEvent just crashes?!? (From: Ondra Cada <email@hidden>)
 >Re: CGEventCreateKeyboardEvent just crashes?!? (From: Eric Schlegel <email@hidden>)
 >Now CGEventCreateKeyboardEvent just doesn't work... (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: When do I have to update the typing attributes?
  • Next by Date: Re: Now CGEventCreateKeyboardEvent just doesn't work...
  • Previous by thread: Now CGEventCreateKeyboardEvent just doesn't work...
  • Next by thread: Re: Now CGEventCreateKeyboardEvent just doesn't work...
  • Index(es):
    • Date
    • Thread