Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BINDEVENT GetKeyState

Status
Not open for further replies.

newtofoxpro

Programmer
Sep 16, 2007
301
0
0
IN
Code:
PUBLIC ofrm
ofrm = CREATEOBJECT("MyForm")
ofrm.show(1)
RETURN

DEFINE CLASS MyForm as Form
    AutoCenter=.T.
	ADD OBJECT txt1 as textbox 
	ADD OBJECT txt2 as textbox WITH Top=50
	ADD OBJECT cmd as commandbutton WITH top = 100, Height=100, Width=thisform.width, Visible=.F.
  	PROCEDURE Init
        DECLARE integer GetKeyState IN User32 integer
  		BINDEVENT(This.HWnd,0x0100,This,"DetectCtrlKeyDn")
 		BINDEVENT(This.HWnd,0x0101,This,"DetectCtrlKeyUp")
  		BINDEVENT(This.HWnd,0x0104,This,"DetectAltKeyDn")
 		BINDEVENT(This.HWnd,0x0105,This,"DetectAltKeyUp")
	ENDPROC
 	PROCEDURE DetectCtrlKeyDn(p1,p2,p3,p4)
	   IF bittest(GetKeyState(0x11),7)
          this.cmd.Caption="Ctrl"
          this.cmd.Visible=.T.
       ENDIF
	PROCEDURE DetectCtrlKeyUp(p1,p2,p3,p4)
	   this.cmd.Visible=.F.
 	PROCEDURE DetectAltKeyDn(p1,p2,p3,p4)
       this.cmd.Caption="Alt"
       this.cmd.Visible=.T.
	PROCEDURE DetectAltKeyUp(p1,p2,p3,p4)
	   this.cmd.Visible=.F.
ENDDEFINE

1. If I press F10 Alt key works. I need only Alt key should work.
2. Arrow keys not working. I need only Ctrl key should work.

What I am missing ? Please help me.

Best Regards.
 
Well, look at the definition of the windows messages you're binding to.

0x0100: 0x0101: 0x0104: 0x0105:
They are not about CTRL and ALT, the first two are about any key while ALT is not pressed the others about any key while ALT is pressed.

Program a handler just outputting p1-p4 and see how these values come in when you press keys. Notice the parameter values will differ for ALT, ALT Gr, Left and Right CTRL key, left and right SHIFT key, when akey is hold down for a while and when pressed in combination with other keys.

Bye, Olaf.

Olaf Doschke Software Engineering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top