Keyboard State

TeeChart for ActiveX, COM and ASP
Post Reply
FP
Newbie
Newbie
Posts: 14
Joined: Mon May 17, 2004 4:00 am

Keyboard State

Post by FP » Wed Jun 09, 2004 1:16 pm

The MousePressed Event seems to pass incorrect values for the Shift Parameter

If combinations of Shift & Ctrl are pressed only one of them are passed.

Is this by design or a small bug?

The Enum (EShift.. something) seems to suggest that the shift and Ctrl key could be sent at once.

I haven't tested the Alt key.

/ F

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Wed Jun 09, 2004 4:00 pm

Hi --

Try:

Code: Select all

Private Sub TChart1_OnKeyDown(ByVal KeyCode As Long, ByVal Shift As TeeChart.EShiftState)
If Shift = ssShift And KeyCode <> 16 Then
    If KeyCode = 17 Then
        MsgBox "This has got to be Shift+Control"
    ElseIf KeyCode = 18 Then
        MsgBox "This has got to be Shift+Alt"
    End If
End If
End Sub
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

FP
Newbie
Newbie
Posts: 14
Joined: Mon May 17, 2004 4:00 am

Correct

Post by FP » Mon Jun 14, 2004 12:08 pm

Chris,

You're right, your code works, however, the code below doesn't work as I expect.

Code: Select all

Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer

Private Sub TChart1_OnMouseDown(ByVal Button As TeeChart.EMouseButton, ByVal Shift As TeeChart.EShiftState, ByVal X As Long, ByVal Y As Long)
'Note that no test for CTRL+SHIFT+ALT, CTRL+SHIFT or CTRL+ALT is done,
    
    
    If (Shift And ssAlt) <> 0 And (Shift And ssShift) <> 0 Then
        'Will never execute
        Debug.Print "Chart Shift+Alt"
    ElseIf Shift = ssAlt Then
        Debug.Print "Chart Alt"
    ElseIf Shift = ssCtrl Then
        Debug.Print "Chart Ctrl"
    ElseIf Shift = ssShift Then
        Debug.Print "Chart Shift"
    Else
        Debug.Print "Chart None"
    End If
    
    If ((GetAsyncKeyState(vbKeyMenu) And &H8000) <> 0) And ((GetAsyncKeyState(vbKeyShift) And &H8000) <> 0) Then
        'will Execute
        Debug.Print "GetAsyncKeyState Alt+Shift"
    ElseIf (GetAsyncKeyState(vbKeyShift) And &H8000) <> 0 Then
        Debug.Print "GetAsyncKeyState Shift"
    ElseIf (GetAsyncKeyState(vbKeyControl) And &H8000) <> 0 Then
        Debug.Print "GetAsyncKeyState Ctrl"
    ElseIf (GetAsyncKeyState(vbKeyMenu) And &H8000) <> 0 Then
        Debug.Print "GetAsyncKeyState Alt"
    Else
        Debug.Print "GetAsyncKeyState None"
    End If
End Sub
Is that by design?

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Mon Jun 14, 2004 3:51 pm

Hi ..
Is that by design?
Yes. The TChart1_OnKeyDown event contains Shift and KeyCode information whereas the TChart1_OnMouseDown event contains Shift and MouseButton information.

So, if you want access to KeyCode information in the TChart1_OnMouseDown then I suggest that you either use the TChart1_OnKeyDown in conjunction with it or you use a Win32 API function to get it for you (such as GetAsyncKeyState).
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

FP
Newbie
Newbie
Posts: 14
Joined: Mon May 17, 2004 4:00 am

Right

Post by FP » Mon Jun 14, 2004 6:52 pm

I accept your anwser Chris, altough I think it is strange that a parameter/enum specified that way (Shift = 1, Alt = 2, Ctrl = 4) doesn't give as much info as possible.

In the mouseevents holding down Shift passes ssShift, holding down Alt passes ssAlt and holding down Shift+Alt passes ssShift.

Still think it's strange, but I'll happily use the API functions since it gives me the result I'm looking for.

Thanks Chris.

/ F

Post Reply