While the mouse is reach in events (Click, DblClick, MouseDown, MouseUp, MouseMove, etc.) the keyboard is very poor in such events.
Keypress can be associated with KeyDown, but for keyUp there is no such an event.
A solution is to use Bindevent() to bind the WM_KEYUP message
ofrm = CREATEOBJECT("MyForm")
SET SYSMENU OFF
DEFINE CLASS MyForm as Form
ADD OBJECT txt as textbox
ADD OBJECT cmd as commandbutton WITH top = 50
* BINDEVENT(This.HWnd,0x0101,This,"detectkeyup") && intercept keyup
BINDEVENT(_vfp.HWnd,0x0101,This,"detectkeyup") && intercept keyup
* p1 = ThisForm.hwnd
* p2 - The message; 257 = 0x101 in this case
* p3 = Virtual-key code
* p4 % 65536 - the number of times the keystroke is autorepeated as a result of the user holding down the key. The repeat count is always 1 for a WM_KEYUP message
* FLOOR(p4 / 65536) % 256 - The scan code. The value depends on the OEM.
* BITTEST(p4, 24) - ndicates whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is .t. if it is an extended key; otherwise, it is .f.
IF TYPE("This.ActiveControl") = "U"
lcObj = "ThisForm"
lcObj = This.ActiveControl.Name
? lcObj,"Virtual-key code",p3,"The scan code",FLOOR(p4 / 65536) % 256,IIF(BITTEST(p4, 24),"Extended key","Normal key")
One final note: WM_KEYDOWN is almost identical, but the value of the message is 0x0100, not 0x0101