Re: CGPostKeyboardEvent strangeness
Re: CGPostKeyboardEvent strangeness
- Subject: Re: CGPostKeyboardEvent strangeness
- From: "Jonathan 'Wolf' Rentzsch" <email@hidden>
- Date: Thu, 11 Nov 2004 09:14:30 -0600
Salánki Benjámin, email@hidden, wrote:
>The problem arises when I try to mix these two functions, so when I
>press my hotkey combo I want to use the CGPostKeyboardEvent functions.
>But here's what happens: I press my key combo and everything works
>fine. I press it again, and nothing happens!! I press it a third time,
>works like a charm, press it a fourth time, nothing again, and so on!!!
Are you attempting to post keystrokes immediately within your hot key
handler? If so, put this code in your handler, prior to any calls to
CGPostKeyboardEvent():
long ignored;
while( AnyKeyDown() ) {
Delay(6, &ignored); // tenth of a second
}
Where AnyKeyDown() is defined as:
static BOOL AnyKeyDown() {
const UInt32 kCapsLockBit = 0x02L;
KeyMap keys;
GetKeys( keys );
return keys[0] || (keys[1] & ~kCapsLockBit) || keys[2] || keys[3];
}
Basically, you're waiting for the user to stop pressing any keys before
you attempt to type anything. I've found attempting to type while the
user is pressing the key results in behavior like what you're seeing.
Keep in mind this will fail if "Secure Keyboard Entry" is enabled in
Terminal.app:
<http://rentzsch.com/macosx/terminalSecureKeyboardEntry>
In this case, I know of no work-around.
| Jonathan 'Wolf' Rentzsch http://rentzsch.com
| Red Shed Software http://redshed.net
| "better" necessarily means "different"
_______________________________________________
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