Results 1 to 16 of 16

Thread: (Resolved) How to detect arrow and shift keys in vb.net

Threaded View

  1. #1

    Thread Starter
    Addicted Member Sanko's Avatar
    Join Date
    Mar 2000
    Location
    Argentina
    Posts
    128

    Resolved (Resolved) How to detect arrow and shift keys in vb.net

    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
    VB Code:
    1. Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
    2.         Const WM_KEYDOWN As Integer = &H100
    3.         Const WM_SYSKEYDOWN As Integer = &H104
    4.         If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
    5.             Select Case (keyData)
    6.                   Case Keys.Left
    7.                        msgbox ("L")
    8.                   Case Keys.Right
    9.                        msgbox ("R")
    10.                   Case Keys.Up
    11.                        msgbox ("U")
    12.                   Case Keys.Down
    13.                        msgbox ("D")
    14.                   Case Keys.Shift
    15.                        msgbox ("S")
    16.                   Case Keys.Control
    17.                        msgbox ("C")
    18. Return MyBase.ProcessCmdKey(msg, keyData)
    19. End Function
    This work only for the arrows keys because if i press Shift or Ctrl keys dont show the message box
    So i change for this
    VB Code:
    1. ' Normally you can handle Key Down Event to trap Keys
    2.     Private Sub AreaTrabajo_Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    3.         MsgBox(e.KeyData.ToString & " pressed. Key Value is ", MsgBoxStyle.Information, "KeyDown Handler")
    4.     End Sub
    If i press the Shift or Control is ok but if i press and arrow key it not work.

    So how i can detect the Arrow and Shift keys pressed together?
    Last edited by Sanko; Jun 2nd, 2006 at 02:10 PM. Reason: Resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width