An Impossible Problem!!! (no KeyDown events!)

I’m revisiting an old program, converting a desktop Mac Carbon program to a desktop Mac Cocoa program, adding HiDPI support, new features, etc. I’m using Xojo2016r1.1. And, I find myself with an Impossible problem! (Famous last words, I know!) Of course, it must be my error, but I can’t find it. The problem is my application is NOT getting KeyDown events from my main (and only) window. I searched my whole project for “keydown”, and I am NOT trapping for keydown events anywhere else, other than the main window. If I put an alert message or a beep in the KeyDown event handler…I get NOTHING if I hit a key. (And, bear in mind, I DO get KeyUP events and the rest of the program is working just fine.)

So, I need a little outside of the box thinking (and I’m obviously stuck IN the box.) What could I have done to prevent my program from feeding me KeyDown events? Is there a “table of allowable events” or some such thing that I"m not aware of? (And, my window is a regular window, not a subclassed window with any customizations, just a plain stock window.) What could possibly prevent me getting keydown events? Any ideas?

What controls are on the window?
One of them is trapping the key events.

(A listbox is the normal culprit)
Which one has the focus?

It’s my guess that a control has the focus and it’s that control is consuming the key down events. Some controls will consume them even if they’re not using them.

Super thoughts! Thanks Jeff and Bob. I’ll check for that. The window includes a text area and a bunch of canvases.

I did some checking based on your comments. My window is composed of a timer, a text area, and a lot of canvases. All of the controls have the Accept Focus property OFF. I also do NOT explicitly do a SetFocus anywhere in my project. So, I guess you could say I lost my focus! With that mind, I put a MyWindow.SetFocus in MyWindow’s Activate and Open events just in case, but I still don’t get keydown events. So, I’m a little lost again. I’ll keep working…I still like the idea of the possibility that a control MUST be consuming my keydown events.

The textArea is getting the KeyDown events. Put something in the TextArea.Keydown and you will see that code fire.

In Cocoa there is a bug that sets the focus to any TextArea or TextField, even when using Clearfocus or Self.Setfocus, or even set focus on a Canvas.

In one of my apps where I needed to catch Keydown, I used an off-view (Top = -40) TextField as trap. All I need to do is to set focus on it, and I have its KeyDown available. To prevent possible Text Overflow, I added this at the end of Keydown :

Me.Text = ""

Otherwise, you can always use Keyboard.AsyncKeydown…

To Jeff, Bob, Roger, Michel…THANK YOU!! You are all right on the money. I’ve only been working on this project as time allows in between other work, but I can’t tell you how long this little bug has hounded me…now fixed, thanks to all you guys. Excellent suggestions.

YES, the problem appears to be a control was consuming my desired Window KeyDown events. (Thanks Jeff and Bob!)

And, YES, the control that was consuming this event does seem to the the TextArea. (Thanks Roger!) The TEXT part should have been a big clue for me, but I was blind to it because that TextArea was marked as READONLY on purpose. I only put display text in that control, never allowed or wanted any input text. Now, I added a KeyDown handler to the TextArea control and put my old Window KeyDown event handler in there instead, and all is well with the world.

And, lastly, YES, I believe this may be a due to a Cocoa bug (Thanks Michel!) as this bug wasn’t a bug when compiled for Carbon in long ago days.

Thank You All Again!

[quote=267498:@Michel Bujardet]To prevent possible Text Overflow, I added this at the end of Keydown :

Me.Text = ""

You can also “Return True” to eat the keys.