vgulielmus
Programmer
I quote from the help:
The KeyPress event does not occur for any combination of keys with the ALT key.
The object with the focus receives the KeyPress event.
A form can receive the KeyPress event in three special cases:
- The form contains no controls, or none of its controls is visible and enabled.
- The form's KeyPreview property is set to True (.T.). The form first receives the KeyPress event, and then the control with focus receives the event.
- The control on the form cannot process a keystroke, for example, when TAB is pressed to move the focus to the next control.
Try my sample posted below.
1) First of all, no control receive combination of keys with the ALT key, but the form do, so that kind of combinations can be processed, but directly in the form's keypress event.
2) Even when KeyPreview=.F., some keys are processed by the form's keypress event, although they are catched in the control's keypress event.
PUBLIC oFrm
oFrm=CREATEOBJECT("MyForm")
oFrm.show()
DEFINE CLASS MyForm as Form
The KeyPress event does not occur for any combination of keys with the ALT key.
The object with the focus receives the KeyPress event.
A form can receive the KeyPress event in three special cases:
- The form contains no controls, or none of its controls is visible and enabled.
- The form's KeyPreview property is set to True (.T.). The form first receives the KeyPress event, and then the control with focus receives the event.
- The control on the form cannot process a keystroke, for example, when TAB is pressed to move the focus to the next control.
Try my sample posted below.
1) First of all, no control receive combination of keys with the ALT key, but the form do, so that kind of combinations can be processed, but directly in the form's keypress event.
2) Even when KeyPreview=.F., some keys are processed by the form's keypress event, although they are catched in the control's keypress event.
PUBLIC oFrm
oFrm=CREATEOBJECT("MyForm")
oFrm.show()
DEFINE CLASS MyForm as Form
KeyPreview=.F.
ADD OBJECT txt1 as TextBox WITH width=200
ADD OBJECT cmd as CommandButton WITH top=40,Caption="\<Click"
ADD OBJECT lst as ListBox WITH left=220
PROCEDURE txt1.KeyPress
PROCEDURE cmd.KeyPress
PROCEDURE lst.KeyPress
PROCEDURE KeyPress
PROCEDURE Init
ENDDEFINEADD OBJECT txt1 as TextBox WITH width=200
ADD OBJECT cmd as CommandButton WITH top=40,Caption="\<Click"
ADD OBJECT lst as ListBox WITH left=220
PROCEDURE txt1.KeyPress
LPARAMETERS nKey,nShift
MESSAGEBOX(This.name,0,STR(nKey)+STR(nShift))
ENDPROCMESSAGEBOX(This.name,0,STR(nKey)+STR(nShift))
PROCEDURE cmd.KeyPress
LPARAMETERS nKey,nShift
MESSAGEBOX(This.name,0,STR(nKey)+STR(nShift))
ENDPROCMESSAGEBOX(This.name,0,STR(nKey)+STR(nShift))
PROCEDURE lst.KeyPress
LPARAMETERS nKey,nShift
MESSAGEBOX(This.name,0,STR(nKey)+STR(nShift))
ENDPROCMESSAGEBOX(This.name,0,STR(nKey)+STR(nShift))
PROCEDURE KeyPress
LPARAMETERS nKey,nShift
MESSAGEBOX('Foxus changed or the current control cannot process the keystroke',0,STR(nKey)+STR(nShift))
* Not catched:
* Textbox
* - Printable keys + left, right, home, end
* - left arrow at the beginning (change focus to the previous control)
* - right arrow at the end (change focus to the next control)
* - Home two times (first jumps to the beggining, second change the focus to the previous control)
* - End two times (first jumps to the end, second change the focus to the next control)
* Command button
* - Hot key, space, Enter, CTRL+Enter
* Listbox
* - Printable keys + up, down, home, end, pgup, pgdown
ENDPROCMESSAGEBOX('Foxus changed or the current control cannot process the keystroke',0,STR(nKey)+STR(nShift))
* Not catched:
* Textbox
* - Printable keys + left, right, home, end
* - left arrow at the beginning (change focus to the previous control)
* - right arrow at the end (change focus to the next control)
* - Home two times (first jumps to the beggining, second change the focus to the previous control)
* - End two times (first jumps to the end, second change the focus to the next control)
* Command button
* - Hot key, space, Enter, CTRL+Enter
* Listbox
* - Printable keys + up, down, home, end, pgup, pgdown
PROCEDURE Init
RAND(-1)
This.lst.AddItem("First item")
This.lst.AddItem("Second item")
This.lst.AddItem("Third item")
ENDPROCThis.lst.AddItem("First item")
This.lst.AddItem("Second item")
This.lst.AddItem("Third item")