I am writing a simple word processor based on the rich edit box demo in SAMPLES\Controls\RichEditBox\. I would like to intercept keystrokes that the user is typing into the rich edit control.
In the DOC under Advanced / Read keyboard and mouse, I saw something that sounded like it might work:
Code: Select all
SET CONTROL <ControlName> OF <FormName> ONKEYEVENT <FuncName>
After the main window definition and before ACTIVATE WINDOW, I added
Code: Select all
SET CONTROL <RichEditBoxName> OF <MainWindowName> ONKEYEVENT MyKeyProc()
To start out, I made MyKeyProc() simply
Code: Select all
MsgInfo("last character = " + HMG_GetLastCharacter())
This behaved strangely. When I typed a character into the rich edit box, I got what looked like an infinite loop of MsgInfo's. The first MsgInfo showed "last character =", i.e. HMG_GetLastCharacter() returned an empty string, when I was expecting it to return the key I just pressed. Every MsgInfo after that showed the last character as the character I typed, but it keep doing this forever. I never was able to type another character and had to kill the program with Task Manager.
Question 1: What is the purpose of SET CONTROL ... ONKEYEVENT? Is it buggy?
Next I got rid of the SET CONTROL statement and tried adding MyKeyProc() as an ON CHANGE method, i.e.
Code: Select all
@ ... RICHEDITBOX ... ON CHANGE MyKeyProc()
This time it behaved better but it was still strange. I got only one MsgInfo for each key I pressed, and as long as I pressed only alphabetic keys, the MsgInfo showed me the right key. But when I pressed Enter, the MsgInfo showed me the last
alpha key that I pressed instead of the carriage return character. When I pressed Enter a second time, the MsgInfo then showed the last character as a carriage return. Similar results occur with Delete, Backspace, Ctrl-Z, etc. If I pressed Enter followed by Ctrl-Z, then the second MsgInfo showed a carriage return. I got no MsgInfo's when I pressed Insert, an arrow key, Home, End, etc.
So it looks like HMG_GetLastCharacter() is buggy. It returns the last character you typed, except when you type a control character, and then it returns the
second last character you typed.
Question 2: Is there any way to intercept keystrokes coming into just one control? I'm aware of ON KEY, but this intercepts keystrokes typed into any control in the window.
I think that the DOC page that lists these features should also mention GetControlHandle().
Kevin