Re: key combinations while the screen is captured
Re: key combinations while the screen is captured
- Subject: Re: key combinations while the screen is captured
- From: Bjoern Kriews <email@hidden>
- Date: Sat, 20 Mar 2004 00:02:48 +0100
On 19.03.2004, at 06:41, Chaz McGarvey wrote:
Hello:
Is there an easy way to have an application notified somehow if a
certain combination of keys has be pressed when the application isn't
the active application and have it work even when another application
has captured the screen? Can services be called upon while an
application has captured the screen? I don't have any full-screen
apps that support services so I don't know... It seems like
applications which put menus on the right side of the menubar don't
work while the screen is captured, so I hope there is an easy way to
go about this without having to do something tricky.
There is a Carbon HotKey API and someone has written a Cocoa Wrapper
for it
called CocoaHotKey3. If you don't find it mail me and I'll send it to
you
in a few days when I'm back home.
Here is what I have available here on the road:
(Taken from the net, source unknown at the moment)
#import <Cocoa/Cocoa.h>
#import <Carbon/Carbon.h>
@interface Controller : NSObject
{
EventHotKeyRef _hotKey;
}
------
#import "Controller.h"
pascal OSStatus MyHotKeyHandler(EventHandlerCallRef
nextHandler,EventRef theEvent,void *userData)
{
Controller *ctrl = (Controller *) userData;
[NSApp activateIgnoringOtherApps: YES];
return noErr;
}
UninstallHotKey(EventHotKeyRef myHotKeyRef) {
UnregisterEventHotKey(myHotKeyRef);
}
EventHotKeyRef InstallHotKey(void *userData) {
// Now lets go setup the hotkey handler, using Carbon APIs (there
is no ObjC Cocoa
// HotKey API as of 10.2.x)
EventTypeSpec eventType;
const UInt32 kMyHotKeyIdentifier='LoIp'; // your choice
const UInt32 kMyHotKey = 37; // 36 = the return key, 37 = l
EventHotKeyRef gMyHotKeyRef;
EventHotKeyID gMyHotKeyID;
EventHandlerUPP gAppHotKeyFunction;
gAppHotKeyFunction = NewEventHandlerUPP(MyHotKeyHandler);
eventType.eventClass = kEventClassKeyboard;
eventType.eventKind = kEventHotKeyPressed;
InstallApplicationEventHandler(gAppHotKeyFunction,1,&eventType,userData,
NULL);
gMyHotKeyID.signature=kMyHotKeyIdentifier;
gMyHotKeyID.id=1;
RegisterEventHotKey(kMyHotKey, cmdKey|optionKey|controlKey,
gMyHotKeyID, GetApplicationEventTarget(), 0, &gMyHotKeyRef);
return gMyHotKeyRef;
}
@implementation Controller
- (void) dealloc {
UninstallHotKey( _hotkey );
}
- (void) awakeFromNib {
_editMode = NO;
_hotkey = InstallHotKey(self);
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.