Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. WM that has to do with pressing the enter key and TAB key.

WM that has to do with pressing the enter key and TAB key.

Scheduled Pinned Locked Moved Visual Basic
csharphtmlquestion
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dilkonika
    wrote on last edited by
    #1

    Hello ! In this list of windows Messages : http://www.pinvoke.net/default.aspx/Constants/WM.html[^] which is the message that has to do with pressing the Enter key and the TAB key? I try with WM_KEYDOWN , but it seems that the enter and the tab key are not handled. Thank you !

    C 1 Reply Last reply
    0
    • D dilkonika

      Hello ! In this list of windows Messages : http://www.pinvoke.net/default.aspx/Constants/WM.html[^] which is the message that has to do with pressing the Enter key and the TAB key? I try with WM_KEYDOWN , but it seems that the enter and the tab key are not handled. Thank you !

      C Offline
      C Offline
      CHill60
      wrote on last edited by
      #2

      It's been a while since I did ought like this but the WM_CHAR message should contain the key that actually went "down" I think

      D 1 Reply Last reply
      0
      • C CHill60

        It's been a while since I did ought like this but the WM_CHAR message should contain the key that actually went "down" I think

        D Offline
        D Offline
        dilkonika
        wrote on last edited by
        #3

        I try the WM_CHAR too , but doesn't work for TAB and Enter.

        C 1 Reply Last reply
        0
        • D dilkonika

          I try the WM_CHAR too , but doesn't work for TAB and Enter.

          C Offline
          C Offline
          CHill60
          wrote on last edited by
          #4

          Er.. yes it does... how are you checking for those keys

          D 1 Reply Last reply
          0
          • C CHill60

            Er.. yes it does... how are you checking for those keys

            D Offline
            D Offline
            dilkonika
            wrote on last edited by
            #5

            Protected Overrides Sub WndProc(ByRef m As Message)
            If m.Msg = WM_CHAR Then
            Return
            End If
            MyBase.WndProc(m)
            End Sub
            End Class

            all the other keys are blocked , but if TAB or Enter key is pressed then MyBase.WNDProc(m) is executed.

            C 1 Reply Last reply
            0
            • D dilkonika

              Protected Overrides Sub WndProc(ByRef m As Message)
              If m.Msg = WM_CHAR Then
              Return
              End If
              MyBase.WndProc(m)
              End Sub
              End Class

              all the other keys are blocked , but if TAB or Enter key is pressed then MyBase.WNDProc(m) is executed.

              C Offline
              C Offline
              CHill60
              wrote on last edited by
              #6

              This will capture all of the keys using the ProcessCmdKey override rather than WndProc

              Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
              Const WM_KEYDOWN As Integer = &H100

                  If ((msg.Msg = WM\_KEYDOWN)) Then
                      Select Case (keyData)
                          Case Keys.Tab
                              Me.Label1.Text = "Tab Key Captured"
                          Case Keys.Enter
                              Me.Label1.Text = "Enter Key Captured"
                          Case Keys.Return
                              Me.Label1.Text = "Return Key Captured"
                          Case Else
                              Me.Label1.Text = keyData.ToString
                      End Select
                  End If
              
                  Return MyBase.ProcessCmdKey(msg, keyData)
              End Function
              

              But I really don't understand your problem as this also works for me.

              Protected Overrides Sub WndProc(ByRef m As Message)
              Const WM_CHAR = &H102
              If m.Msg = WM_CHAR Then
              Return
              End If
              MyBase.WndProc(m)
              End Sub

              D 2 Replies Last reply
              0
              • C CHill60

                This will capture all of the keys using the ProcessCmdKey override rather than WndProc

                Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
                Const WM_KEYDOWN As Integer = &H100

                    If ((msg.Msg = WM\_KEYDOWN)) Then
                        Select Case (keyData)
                            Case Keys.Tab
                                Me.Label1.Text = "Tab Key Captured"
                            Case Keys.Enter
                                Me.Label1.Text = "Enter Key Captured"
                            Case Keys.Return
                                Me.Label1.Text = "Return Key Captured"
                            Case Else
                                Me.Label1.Text = keyData.ToString
                        End Select
                    End If
                
                    Return MyBase.ProcessCmdKey(msg, keyData)
                End Function
                

                But I really don't understand your problem as this also works for me.

                Protected Overrides Sub WndProc(ByRef m As Message)
                Const WM_CHAR = &H102
                If m.Msg = WM_CHAR Then
                Return
                End If
                MyBase.WndProc(m)
                End Sub

                D Offline
                D Offline
                dilkonika
                wrote on last edited by
                #7

                Thank you ! The problem with my code is that all other keys are blocked for the control , except the TAB key and Enter key. If you have test my code , you should see that for the control , all the other keys are blocked inside the IF . But for Tab key and Enter key , the IF condition is always false , and the standart WNDProc is executed.

                1 Reply Last reply
                0
                • C CHill60

                  This will capture all of the keys using the ProcessCmdKey override rather than WndProc

                  Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
                  Const WM_KEYDOWN As Integer = &H100

                      If ((msg.Msg = WM\_KEYDOWN)) Then
                          Select Case (keyData)
                              Case Keys.Tab
                                  Me.Label1.Text = "Tab Key Captured"
                              Case Keys.Enter
                                  Me.Label1.Text = "Enter Key Captured"
                              Case Keys.Return
                                  Me.Label1.Text = "Return Key Captured"
                              Case Else
                                  Me.Label1.Text = keyData.ToString
                          End Select
                      End If
                  
                      Return MyBase.ProcessCmdKey(msg, keyData)
                  End Function
                  

                  But I really don't understand your problem as this also works for me.

                  Protected Overrides Sub WndProc(ByRef m As Message)
                  Const WM_CHAR = &H102
                  If m.Msg = WM_CHAR Then
                  Return
                  End If
                  MyBase.WndProc(m)
                  End Sub

                  D Offline
                  D Offline
                  dilkonika
                  wrote on last edited by
                  #8

                  sorry but I can't use your function ProcessCMD. The reason is that I'm usng NativeWindow , and when I try to use your function , I get an error 'ProcessCmdKey' is not a member of 'System.Windows.Forms.NativeWindow'. What can I do ? This is my whole class that actually I'm using :

                  Class NW
                  Inherits NativeWindow
                  Public Sub New(hwnd As IntPtr)
                  AssignHandle(hwnd)
                  End Sub
                  Const WM_NCHITTEST As Integer = &H84
                  Const WM_CHAR As Integer = &H102
                  Protected Overrides Sub WndProc(ByRef m As Message)
                  If m.Msg = WM_NCHITTEST OrElse m.Msg = WM_CHAR Then
                  Return
                  End If
                  MyBase.WndProc(m)
                  End Sub

                  End Class
                  
                  C 1 Reply Last reply
                  0
                  • D dilkonika

                    sorry but I can't use your function ProcessCMD. The reason is that I'm usng NativeWindow , and when I try to use your function , I get an error 'ProcessCmdKey' is not a member of 'System.Windows.Forms.NativeWindow'. What can I do ? This is my whole class that actually I'm using :

                    Class NW
                    Inherits NativeWindow
                    Public Sub New(hwnd As IntPtr)
                    AssignHandle(hwnd)
                    End Sub
                    Const WM_NCHITTEST As Integer = &H84
                    Const WM_CHAR As Integer = &H102
                    Protected Overrides Sub WndProc(ByRef m As Message)
                    If m.Msg = WM_NCHITTEST OrElse m.Msg = WM_CHAR Then
                    Return
                    End If
                    MyBase.WndProc(m)
                    End Sub

                    End Class
                    
                    C Offline
                    C Offline
                    CHill60
                    wrote on last edited by
                    #9

                    Sorry - I'm about to head off to the airport and won't get a chance to look at this properly. My advice is to post a question in Quick Answers forum - put in a link to this thread and include the code that you have posted here (you could also post the code I suggested and explain that it didn't work, so everything is in one place). Hopefully someone else will be able to pick it up while I'm away. P.S. - If anyone tells you off for cross-posting point them to this post and I'll take the flack :)

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups