Hi i have this problem developing a custom control.
1) I need to detect if an up, down, left or right arrow is pressed.
2) And also i need to detect if i have pressed Shift+ Up or Shift + Left or Shift + Right or Shift +Down
1) Only detect 1 key pressed
2) Detect 2 keys Shif + Arrow pressed
So i search and found this to detect the arrows keys
This work only for the arrows keys because if i press Shift or Ctrl keys dont show the message boxVB Code:
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean Const WM_KEYDOWN As Integer = &H100 Const WM_SYSKEYDOWN As Integer = &H104 If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then Select Case (keyData) Case Keys.Left msgbox ("L") Case Keys.Right msgbox ("R") Case Keys.Up msgbox ("U") Case Keys.Down msgbox ("D") Case Keys.Shift msgbox ("S") Case Keys.Control msgbox ("C") Return MyBase.ProcessCmdKey(msg, keyData) End Function
So i change for this
If i press the Shift or Control is ok but if i press and arrow key it not work.VB Code:
' Normally you can handle Key Down Event to trap Keys Private Sub AreaTrabajo_Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown MsgBox(e.KeyData.ToString & " pressed. Key Value is ", MsgBoxStyle.Information, "KeyDown Handler") End Sub
So how i can detect the Arrow and Shift keys pressed together?




Reply With Quote