Faceți căutări pe acest blog

vineri, 18 august 2017

Easter eggs (2)

The next issue to solve is to distinguish between left ctrl and right ctrl, generally speaking the extended keys.
This purpose is served by the p4 parameter. To identify such keys, use BITTEST(p4, 24)
When is .T., then an extended keys (like right ctrl) is pressed, otherwise an "ordinary" key (like left ctrl) is pressed.

The next example capture Right Ctrl + P +M and ignores Left Ctrl + P + M.



CLEAR
PUBLIC ofrm
ofrm = CREATEOBJECT("myform")
ofrm.show()

DEFINE CLASS myform as form
      Autocenter = .T.
      lCtrl = .F. && .T. while CTRL is down (pressed)
      lM = .F. && .T. while M is down (pressed)
      lP = .F. && .T. while P is down (pressed)
      ADD OBJECT txt1 as textbox
      ADD OBJECT cmd as commandbutton WITH top = 50
      PROCEDURE init
            UNBINDEVENTS(This.hwnd)
            BINDEVENT(This.hwnd,0x0100,This,"detectkeydown")
            BINDEVENT(This.hwnd,0x0101,This,"detectkeyup")
      ENDPROC
      PROCEDURE detectkeydown
            LPARAMETERS p1,p2,p3,p4
            * p3 = Virtual-key code
            * 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 p3 = 0x11 AND  BITTEST(p4, 24) && right Ctrl is pressed
                  This.lCtrl = .T.
            ENDIF
            IF p3 = 0x4D && M is pressed
                  This.lM = .T.
            ENDIF
            IF p3 = 0x50 && P is pressed
                  This.lP = .T.
            ENDIF
            IF This.lCtrl AND This.lM AND This.lP
                  ACTIVATE SCREEN
                  ? 'Bingo!'
                  ? 'A Right CTRL+P+M occures'
            ENDIF
      ENDPROC
      PROCEDURE detectkeyup
            LPARAMETERS p1,p2,p3,p4
            * p3 = Virtual-key code
            * 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 p3 = 0x11 AND  BITTEST(p4, 24) && Ctrl is released
                  This.lCtrl = .F.
            ENDIF
            IF p3 = 0x4D && M is released
                  This.lM = .F.
            ENDIF
            IF p3 = 0x50 && P is released
                  This.lP = .F.
            ENDIF
      ENDPROC
ENDDEFINE

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