Faceți căutări pe acest blog

Se afișează postările cu eticheta windows messages. Afișați toate postările
Se afișează postările cu eticheta windows messages. Afișați toate postările

marți, 22 august 2017

Easter eggs (4)

I found a pattern. The keys that are grouped ("neighbors") behaves similarly, especially those in the median part and the right part of the alphanumeric region. I mean it's difficult to catch three of them pressed simultaneously. Any combination of two, or two + other key shows no problem.

Using an US keyboard, the alphanumeric region
4 5 6 7
E R T Y U
D F G H J K
C V B N M ,

0 - = (zero, minus, equal)
P [ ]
L ; '

The numeric keypad
/ * -
0 . 2
0 . 3
1 2 4
1 2 5
2 4 5
a.s.o

The test code used by me (click or press the command button to experiment different combinations):



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

DEFINE CLASS myform as form
      Autocenter = .T.
      l1 = .F. && .T. while key #1 is pressed
      l2 = .F. && .T. while key #2 is pressed
      l3 = .F. && .T. while key #3 is pressed
      ln1 = -1 && Store scan code 1
      ln2 = -1 && Store scan code 2
      ln3 = -1 && Store scan code 3
      ADD OBJECT txt1 as textbox
      ADD OBJECT cmd as commandbutton WITH top = 50, caption = "Reset" && reset the combination
      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
            IF This.ln3 = -1 AND !INLIST(This.ln1, -1, m.p3) AND !INLIST(This.ln2, -1, m.p3)
                  This.ln3 = m.p3
            ENDIF
            IF m.p3 = This.ln3
                  This.l3 = .T.
            ENDIF

            IF This.ln2 = -1 AND !INLIST(This.ln1, -1, m.p3)
                  This.ln2 = m.p3
            ENDIF
            IF m.p3 = This.ln2
                  This.l2 = .T.
            ENDIF

            IF This.ln1 = -1
                  This.ln1 = m.p3
            ENDIF
            IF m.p3 = This.ln1
                  This.l1 = .T.
            ENDIF

            ACTIVATE SCREEN
            ? m.p3
            IF This.l1 AND This.l2 AND This.l3
                  ? 'Bingo!'
                  ? 'An ' + LTRIM(STR(This.ln1)) + '+' + LTRIM(STR(This.ln2)) + '+' + LTRIM(STR(This.ln3)) + ' occures'
            ENDIF
                  ACTIVATE SCREEN
            ?This.l1 ,This.l2 ,This.l3
      ENDPROC
      PROCEDURE detectkeyup
            LPARAMETERS p1,p2,p3,p4
            * p3 = Virtual-key code
            IF p3 = This.ln1
                  This.l1 = .F.
            ENDIF
            IF p3 = This.ln2
                  This.l2 = .F.
            ENDIF
            IF p3 = This.ln3
                  This.l3 = .F.
            ENDIF
      ENDPROC
      PROCEDURE cmd.click
            STORE -1 TO ThisForm.ln1, ThisForm.ln2, ThisForm.ln3
            STORE .F. TO ThisForm.l1, ThisForm.l2, ThisForm.l3
      ENDPROC
ENDDEFINE

Update
The previous test was on a Dell keyboard with a US layout (Windows 7 32 bit).
I repeated the same test, but this time using a Fujitsu keyboard with a German layout (Windows 10 prof 64 bit). And what do you know? I managed to catch a 3+4+5. Not easy, but Bingo!
The patterns are almost the same.
Ha! So most probably it's a hardware issue.

Later
A new test using a Genius keyboard (Windows 10 home 32 bit), with an US layout, behaves poorly.
Another test. A HP notebook (Windows 10 home 64 bit) with a Germanic layout, behaves even better than Fujitsu.
A final test using a Lenovo laptop (Windows 10 home 64 bit) with an US layout, behaves poorly.

Again
This article https://en.wikipedia.org/wiki/Rollover_(key) explains everything.

vineri, 18 august 2017

Easter eggs (3)

Peculiarity

I can't catch the 3+4+5. I do any combination of two, i.e. 3+4, 3+5 and 4+5, but not all three of them.
Please try the next demo


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

DEFINE CLASS myform as form
      Autocenter = .T.
      l3 = .F. && .T. while 3 is down (pressed)
      l4 = .F. && .T. while 4 is down (pressed)
      l5 = .F. && .T. while 5 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
            IF p3 = 0x33 && 3 is pressed
                  This.l3 = .T.
            ENDIF
            IF p3 = 0x34 && 4 is pressed
                  This.l4 = .T.
            ENDIF
            IF p3 = 0x35 && 5 is pressed
                  This.l5 = .T.
            ENDIF
            IF This.l3 AND This.l4 AND This.l5
                  ACTIVATE SCREEN
                  ? 'Bingo!'
                  ? 'An 3+4+5 occures'
            ENDIF
                  ACTIVATE SCREEN
            ?This.l3 ,This.l4 ,This.l5
      ENDPROC
      PROCEDURE detectkeyup
            LPARAMETERS p1,p2,p3,p4
            * p3 = Virtual-key code
            IF p3 = 0x33 && 3 is released
                  This.l3 = .F.
            ENDIF
            IF p3 = 0x34 && 4 is released
                  This.l4 = .F.
            ENDIF
            IF p3 = 0x35 && 5 is released
                  This.l5 = .F.
            ENDIF
      ENDPROC
ENDDEFINE

  Oddly, the keys from the numeric keypad behaves normally.



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

DEFINE CLASS myform as form
      Autocenter = .T.
      l3 = .F. && .T. while 3 is down (pressed)
      l4 = .F. && .T. while 4 is down (pressed)
      l5 = .F. && .T. while 5 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
            IF p3 = 0x63 && 3 is pressed
                  This.l3 = .T.
            ENDIF
            IF p3 = 0x64 && 4 is pressed
                  This.l4 = .T.
            ENDIF
            IF p3 = 0x65 && 5 is pressed
                  This.l5 = .T.
            ENDIF
            IF This.l3 AND This.l4 AND This.l5
                  ACTIVATE SCREEN
                  ? 'Bingo!'
                  ? 'An 3+4+5 occures'
            ENDIF
                  ACTIVATE SCREEN
            ?This.l3 ,This.l4 ,This.l5
      ENDPROC
      PROCEDURE detectkeyup
            LPARAMETERS p1,p2,p3,p4
            * p3 = Virtual-key code
            IF p3 = 0x63 && 3 is released
                  This.l3 = .F.
            ENDIF
            IF p3 = 0x64 && 4 is released
                  This.l4 = .F.
            ENDIF
            IF p3 = 0x65 && 5 is released
                  This.l5 = .F.
            ENDIF
      ENDPROC
ENDDEFINE