Faceți căutări pe acest blog

luni, 22 iunie 2015

Detect KeyUp (Like MouseUp)

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

PUBLIC ofrm
ofrm = CREATEOBJECT("MyForm")
SET SYSMENU OFF
ofrm.show()

DEFINE CLASS MyForm as Form
    ADD OBJECT txt as textbox
    ADD OBJECT cmd as commandbutton WITH top = 50
    PROCEDURE Init
*        BINDEVENT(This.HWnd,0x0101,This,"detectkeyup") && intercept keyup
        BINDEVENT(_vfp.HWnd,0x0101,This,"detectkeyup") && intercept keyup
    ENDPROC
    PROCEDURE detectkeyup
        LPARAMETERS p1,p2,p3,p4
        * 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"
        ELSE
            lcObj = This.ActiveControl.Name
        ENDIF
        ACTIVATE SCREEN
        ? lcObj,"Virtual-key code",p3,"The scan code",FLOOR(p4 / 65536) % 256,IIF(BITTEST(p4, 24),"Extended key","Normal key")
    ENDPROC
ENDDEFINE


One final note: WM_KEYDOWN is almost identical, but the value of the message is 0x0100, not 0x0101

Biblio
http://www.foxite.com/archives/detect-keypress-release-0000424382.htm
http://www.tek-tips.com/faqs.cfm?fid=7701
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646281%28v=vs.85%29.aspx
http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html
https://msdn.microsoft.com/en-us/library/aa925780.aspx

Related posts
http://praisachion.blogspot.com/2017/08/easter-eggs-4.html
http://praisachion.blogspot.com/2017/08/easter-eggs-3.html
http://praisachion.blogspot.com/2017/08/easter-eggs-2.html
http://praisachion.blogspot.com/2017/08/easter-eggs-1.html

http://praisachion.blogspot.com/2016/02/interceptin-ctrlshiftenter.html
http://praisachion.blogspot.com/2015/06/detect-keyup-like-mouseup.html
http://praisachion.blogspot.com/2015/01/how-can-i-prevent-undocking-docked-form.html

Niciun comentariu:

Trimiteți un comentariu