Catching events in an empty window.
Catching events in an empty window.
- Subject: Catching events in an empty window.
- From: "Daniel T. Staal" <email@hidden>
- Date: Fri, 3 Aug 2007 20:18:23 -0400 (EDT)
- Importance: Normal
I have a full-screen borderless window that I'm using as a drawing area,
and I want to capture keypresses. (Think a game: The screen changes
constantly, partially depending on what keys have been pressed.)
The window is created entirely in code, and has _nothing_ on it (I'm
drawing into the background directly). All my keypresses are going to the
window behind it, no matter what I try. Is there a way to get them? I've
tried setting a keyDown event in the window itself, or setting the class
that opens it to be the delegate and first responder for the window, but
neither does anything.
Window init code:
========================================================
CGDisplayErr err;
err = CGCaptureAllDisplays(); // 'Capture' the screens.
if (err != CGDisplayNoErr) {
return;
}
// Create the full-screen window.
NSRect winRect = [mainScreen frame];
window = [[NSWindow alloc] initWithContentRect:winRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO
screen:[NSScreen mainScreen]];
// Establish the window attributes.
[window setReleasedWhenClosed:YES];
[window setDisplaysWhenScreenProfileChanges:YES];
[window setDelegate:self];
// Make the screen window the current document window.
win_controller = [[NSWindowController alloc] initWithWindow:window];
// The window has to be above the level of the shield window.
int32_t shieldLevel = CGShieldingWindowLevel();
[window setLevel:shieldLevel];
// Show the window.
[window makeKeyAndOrderFront:self];
if ( ![window makeFirstResponder:self] ) {
NSLog(@"Unable to make first responder");
}
========================================================
Daniel T. Staal
---------------------------------------------------------------
This email copyright the author. Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes. This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden