ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5
part 6
part 7
part 8


4 - Keys and Focus

Another aspect of programming for key recognition is focus. In the sample program, key presses are displayed in a scrolling list. The reason all keys (including text), go there instead of the edit field at the bottom is because of the initial focus.

When the program starts up, the edit control does not have the keyboard focus. This focus means keystrokes would be sent there for processing first, before the form gets a 'look' at them. To change that, just tap in the control to give it focus. From then on, keyboard entries are first seen by the edit control - they will display there if normal characters, and the messages will never reach the message loop of the parent form and get displayed. On the other hand, special key codes (such as the jog wheel keys) will still go to the parent, since the edit control doesn't know how to process them, instead passing them on up the message chain.

The moral of this is to always use the window command SetFocus() to make sure keystrokes go to the appropriate object. One easy to make mistake is to forget to use SetFocus() before expecting key entries. Fortunately it's easy to detect, since in that case keystrokes won't be received properly.

Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice