Correct way of handling key down

Moderator
Posts: 365
Joined: 2002.04
Post: #16
arekkusu Wrote:Has anyone noticed this bug's revival in 10.3.7? Some apps stop responding to keyboard input here after using the system for a while...
Funny you should mention that... I noticed that it had returned just the other day (although I'm still using 10.3.6). It took me a while to figure out what the problem was: the Terminal app. Quit it and everything returns to normal.

This may just be something peculiar to my machine, though. Several other people who tried the same thing said that it didn't happen for them.

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #17
Hm... I have had Terminal open every time it's occurred. I'll try that next time it happens.
Quote this message in a reply
Moderator
Posts: 3,577
Joined: 2003.06
Post: #18
I used to be able to log in to an app called Aquamon and then log back out and the keys would come back. I don't know if this is the same case since I haven't had the key problem in a year or two.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #19
It appears to be due to Terminal's "Secure Keyboard Entry" feature-- when active, GetKeys() is disabled globally which breaks some games etc.

So, Terminal can stay running, just don't use secure entry.
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #20
Hm, I get a 404 on that server. Nevertheless, very interesting information. Thanks for digging it out!
Quote this message in a reply
spaceb
Unregistered
 
Post: #21
The main reason to pool for keyboard input with GetKeys(), instead of using the standard key events, is to check whether a "modifier key" (such as shift or control) is being held down. This is needed because modifier keys don't generate key events when they are pressed. For instance, If you wanted to make a character jump when shift is pressed, you would have to use GetKeys() in a polling loop. Hope this helps!
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #22
You can use the Carbon Event kEventClassKeyboard/kEventRawKeyModifiersChanged to be notified when the modifiers change. No polling necessary.

- Alex Diener
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #23
arekkusu Wrote:It appears to be due to Terminal's "Secure Keyboard Entry" feature-- when active, GetKeys() is disabled globally which breaks some games etc.

So, Terminal can stay running, just don't use secure entry.
Thanks for tracking that information down! I had indeed turned on Secure Keyboard Entry for the reason Rentzsch mentions in his article ("Don't I want my keyboard entry to be secure all the time?"). Turning it off does fix the problem. Smile

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #24
spaceb Wrote:This is needed because modifier keys don't generate key events when they are pressed.
They certainly do. What do you think [NSResponder flagsChanged:] is for?

There's no need to poll. Don't do it, it just wastes CPU and makes me angry.
Quote this message in a reply
spaceb
Unregistered
 
Post: #25
ThemsAllTook Wrote:You can use the Carbon Event kEventClassKeyboard/kEventRawKeyModifiersChanged to be notified when the modifiers change. No polling necessary.

- Alex Diener

Ah, I'm sorry - I didn't realize that this was possible under Carbon. Thanks for the info!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  NSWindow frame message not returning correct values after moving the window Svarog 6 4,866 Jan 7, 2007 06:41 PM
Last Post: OneSadCookie
  CB Key handling skyhawk 6 3,608 Aug 12, 2003 10:13 AM
Last Post: kelvin