keydown event never fires on Win7

I am relateively new to programming for Windows so please bare with me.

I have a window that I am trying to use the keydown event in. In my event I only have msgbox key right now (to show what key is being pressed). It never fires. so I put the same code in keyup to make sure keydown wasnt firing but keyup was. still nada.

my forums search-fu suggested that a listbox might be eating the keys. On that window I have no listboxes. checkboxes, textareas, textfields, labels, and bevel buttons. Now on the main window that launches this secondary window has a listbox. but I “hide” that window when I launch this window.

what am I doing wrong? it is something simple.

have a good weekend!!
sb

Do you return true?

Does the control have the focus?

@scott

just tried msgbox key (no return true) and it does work as expected Xojo 2015R3.1 Windows 7 (using just default Window)

I’m with Markus and sounds like a focus issue

[quote=231196:@Markus Winter]Do you return true?

Does the control have the focus?[/quote]

I do return true on the keydown but dont return on keyup.

not disagreeing with you. but cant see how the only window visable doesnt have focus. again I am probably doing something stupid.

Focus +1. It is very possible for the window itself to lose focus. Windows Desktop tends to grab focus so you can navigate the icons with the keyboard.

Especially if there are no controls on the window that can receive focus. The OS says, Oh, this window doesn’t need focus…

I created a new project with no control on the window. Added KeyDown with MsgBox Key into it. Fires very nicely.

However, when I add a TextField, it steals the event.

You may want to put a System.debuglog in the GotFocus event of each of your controls. Maybe one of them you do not think gets focus is doing it. A ClearFocus could largely improve the situation as well.

Finally, in order to alleviate this keydown nitty-gritty, if what you need is to monitor the keys, sometimes a timer that checks Keyboard.AsyncKeyDown can do wonder. Or a menuitem shortcut.

@Tim Hare and @Michel Bujardet thanks for the ideas. I will try them.

on a side note, I rather program for Mac. I tend not to have these odd issues. And I dont think my issues with Windows is a Xojo thing but a Windows thing. I blame Redmond and I am only slightly sarcastic about that statement.

thanks all for the help!

Never hurts to blame Bill Gates :wink:

I remember you may need to call window.setFocus method to have the keydown event to work on Windows.

Where?

Can’t be GotFocus or KeyDown, so I presume the MouseEnter event?

For me after calling ClearFocus on Windows I needed to call SetFocus on window to have key events work.
Maybe you call SetFocus in Windows in some places?

[quote=231444:@scott boss] I dont think my issues with Windows is a Xojo thing but a Windows thing. I blame Redmond.
[/quote]
You are quite correct.