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. How to Capture the Back Button

How to Capture the Back Button

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
5 Posts 2 Posters 1 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.
  • T Offline
    T Offline
    Thomas Wells
    wrote on last edited by
    #1

    Many mice have a back button. Many applications implement a goback kind of function, mostly browsers. I'd like to capture a mouse back button so I can offer a similar functionality. Any idea how to tell if the mouse "back" button has been pressed?

    D 1 Reply Last reply
    0
    • T Thomas Wells

      Many mice have a back button. Many applications implement a goback kind of function, mostly browsers. I'd like to capture a mouse back button so I can offer a similar functionality. Any idea how to tell if the mouse "back" button has been pressed?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Well, you'd have to override your Form's WndProc and check for two messages. m.Msg 523 is WM_XBUTTONDOWN and 524 is WM_XBUTTONUP. This is, hopefully obvious, the pressing and releasing of any of the extra buttons on the mouse. When receiving either of these messages, look at the high-order word in the m.WParam property of the message. This will tell you which mouse "extra" button was pressed/released.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      T 2 Replies Last reply
      0
      • D Dave Kreskowiak

        Well, you'd have to override your Form's WndProc and check for two messages. m.Msg 523 is WM_XBUTTONDOWN and 524 is WM_XBUTTONUP. This is, hopefully obvious, the pressing and releasing of any of the extra buttons on the mouse. When receiving either of these messages, look at the high-order word in the m.WParam property of the message. This will tell you which mouse "extra" button was pressed/released.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        T Offline
        T Offline
        Thomas Wells
        wrote on last edited by
        #3

        I had considered intercepting the xbutton messages but the value of a button is programmable on most mice isn't it? Doesn't that mean that some other message is being sent which means "Back". Coding a specific mouse button would not use a mouse's programmed setting.

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          Well, you'd have to override your Form's WndProc and check for two messages. m.Msg 523 is WM_XBUTTONDOWN and 524 is WM_XBUTTONUP. This is, hopefully obvious, the pressing and releasing of any of the extra buttons on the mouse. When receiving either of these messages, look at the high-order word in the m.WParam property of the message. This will tell you which mouse "extra" button was pressed/released.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          T Offline
          T Offline
          Thomas Wells
          wrote on last edited by
          #4

          I've gotten a bit closer. It looks like what I want is a virtual key, VK_BROWSER_BACK. It is also recognized as a key modifier, Keys.BrowserBack. These don't seem to come through in the OnKeyDown override. I've seen code samples that implement IMessageFilter.

          Public Class Form2
          Implements IMessageFilter

          Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean \_
                Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
              Dim keyCode As Keys = CType(m.WParam.ToInt32(), Keys) And Keys.KeyCode
              If keyCode = Keys.BrowserBack Then
                  Console.WriteLine("I found it")
              End If
          End Function
          

          End Class

          Of course this doesn't work either. It never finds Keys.BrowserBack. I've seen m.WParam have values 65568(10020h) & 65536(10000h) when I press my browser back key (xButton on the mouse). Any ideas?

          modified on Monday, March 9, 2009 2:25 PM

          D 1 Reply Last reply
          0
          • T Thomas Wells

            I've gotten a bit closer. It looks like what I want is a virtual key, VK_BROWSER_BACK. It is also recognized as a key modifier, Keys.BrowserBack. These don't seem to come through in the OnKeyDown override. I've seen code samples that implement IMessageFilter.

            Public Class Form2
            Implements IMessageFilter

            Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean \_
                  Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
                Dim keyCode As Keys = CType(m.WParam.ToInt32(), Keys) And Keys.KeyCode
                If keyCode = Keys.BrowserBack Then
                    Console.WriteLine("I found it")
                End If
            End Function
            

            End Class

            Of course this doesn't work either. It never finds Keys.BrowserBack. I've seen m.WParam have values 65568(10020h) & 65536(10000h) when I press my browser back key (xButton on the mouse). Any ideas?

            modified on Monday, March 9, 2009 2:25 PM

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            The only thing I can suggest would be the documentation on WM+_XBUTTONDOWN[^]. Since the values in the Params are the result of the combining of smaller fields into a 32-bit value, you have to do some math to figure out what each of these fields means.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            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