How to Capture the Back Button
-
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?
-
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?
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 them.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 -
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 them.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, 2008I 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.
-
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 them.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, 2008I'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 IMessageFilterPublic 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
-
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 IMessageFilterPublic 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
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