Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Keypress track CTRL+1
Message
From
22/07/2011 07:47:01
 
 
To
21/07/2011 17:53:17
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01518850
Message ID:
01518891
Views:
59
>>Hello,
>>
>>I tried to write a code in the Keypress event of the form which would track when the user presses a number with the CTRL button pressed. I was very surprised that the keypress event does not get triggered when pressing the CTRL and 1 key, up to Ctrl + 9. Only Ctrl+0 does raise the keypress event.
>>
>>Is there a workaround, or something that I overlook?
>
>Hi Christian,
>personally, I have no other idea to solve this problem except using API function in Timer object
>Would you try this?
>
>
>loForm = CREATEOBJECT("Form1")
>loForm.Show()
>READ EVENTS
>
>DEFINE CLASS Form1 AS form
>  Caption = "Form1"
>  AutoCenter = .T.
>  KeyPreview = .T.
>  Name = "Form1"
>
>  ADD OBJECT label1 AS label WITH ;
>    AutoSize = .T., ;
>    BackStyle = 0, ;
>    Caption = "Shift-Alt-Ctrl:", ;
>    Height = 17, ;
>    Left = 12, ;
>    Top = 36, ;
>    Width = 69, ;
>    Name = "Label1"
>
>  ADD OBJECT label2 AS label WITH ;
>    AutoSize = .T., ;
>    BackStyle = 0, ;
>    Caption = "KeyCode:", ;
>    Height = 17, ;
>    Left = 12, ;
>    Top = 72, ;
>    Width = 55, ;
>    Name = "Label2"
>
>  ADD OBJECT text1 AS textbox WITH ;
>    Height = 23, ;
>    Left = 96, ;
>    TabIndex = 2, ;
>    Top = 36, ;
>    Width = 100, ;
>    Name = "Text1"
>
>  ADD OBJECT text2 AS textbox WITH ;
>    Height = 23, ;
>    Left = 96, ;
>    TabIndex = 3, ;
>    Top = 72, ;
>    Width = 100, ;
>    Name = "Text2"
>
>  ADD OBJECT command1 AS commandbutton WITH ;
>    Top = 204, ;
>    Left = 276, ;
>    Height = 27, ;
>    Width = 84, ;
>    Caption = "Command1", ;
>    TabIndex = 1, ;
>    Name = "Command1"
>
>  ADD OBJECT timer1 AS timer WITH ;
>    Top = 0, ;
>    Left = 0, ;
>    Height = 23, ;
>    Width = 23, ;
>    Interval = 50, ;
>    Name = "Timer1"
>
>  PROCEDURE Destroy
>    CLEAR EVENTS
>  ENDPROC
>
>  PROCEDURE KeyPress
>    LPARAMETERS nKeyCode, nShiftAltCtrl
>    IF nShiftAltCtrl = 2 AND BETWEEN(nKeyCode, 48, 57)
>      this.Text1.Value = nShiftAltCtrl
>      this.Text2.Value = nKeyCode
>    ELSE
>      this.Text1.Value = 0
>      this.Text2.Value = 0
>    ENDIF
>  ENDPROC
>
>  PROCEDURE timer1.Init
>    DECLARE LONG GetAsyncKeyState IN WIN32API LONG
>  ENDPROC
>
>  PROCEDURE timer1.Timer
>    this.Enabled = .F.
>    #define VK_CONTROL 0x11
>    IF BITAND(GetAsyncKeyState(VK_CONTROL), 0x8000) != 0
>      FOR m.i = 48 TO 57
>        IF BITAND(GetAsyncKeyState(m.i), 0x8000) != 0
>          RAISEEVENT(thisform, "KeyPress", m.i, 2)
>          EXIT
>        ENDIF
>      ENDFOR
>    ENDIF
>    this.Enabled = .T.
>  ENDPROC
>ENDDEFINE
>
>
>
>Regards,
>Ony

Thanks, that is really great!
Christian Isberner
Software Consultant
Previous
Reply
Map
View

Click here to load this message in the networking platform