Page 1 of 1

Keyboard State

Posted: Wed Jun 09, 2004 1:16 pm
by 9082517
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

Posted: Wed Jun 09, 2004 4:00 pm
by Chris
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

Correct

Posted: Mon Jun 14, 2004 12:08 pm
by 9082517
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?

Posted: Mon Jun 14, 2004 3:51 pm
by Chris
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).

Right

Posted: Mon Jun 14, 2004 6:52 pm
by 9082517
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