How to recognize mouse buttons 4-5 clicks on webbrowser control?-VBForums
Results 1 to 10 of 10

Thread: How to recognize mouse buttons 4-5 clicks on webbrowser control?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    159

    How to recognize mouse buttons 4-5 clicks on webbrowser control?

    In my software there's a WebBrowser control and I'd like the mosue buttons 4 and 5 to do back/forward like in other browsers. I added code to handle the clicks on the main form but it never gets triggered.

    How would I add this feature?

    Thanks

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How to recognize mouse buttons 4-5 clicks on webbrowser control?

    What are you using to detect buttons 4 and 5?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    159

    Re: How to recognize mouse buttons 4-5 clicks on webbrowser control?

    I'm not using anything now, I don't know how to do this, I'd like to know how.

    Thank you

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    9,113

    Re: How to recognize mouse buttons 4-5 clicks on webbrowser control?

    What kind of a mouse has 5 buttons on it? My mouse has 4 buttons: Left button, Right button, Scrollbar button, and Previous/Current toggle button. What would button 5 do?
    Last edited by jmsrickland; May 5th, 2012 at 12:38 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    159

    Re: How to recognize mouse buttons 4-5 clicks on webbrowser control?

    Quote Originally Posted by jmsrickland View Post
    What kind of a mouse has 5 buttons on it? My mouse has 4 buttons: Left button, Right button, Scrollbar button, and Previous/Current toggle button. What would button 5 do?
    That does add up to 5:

    "Left button (1), Right button (2), Scrollbar button (3), and Previous (4)/Current (5) toggle button"

    I assume you meant "Forward" and not "Current" as a button that brings you where you currently are wouldn't do anything lol.

    The 4th and 5th buttons do previous/forward in every web browser I've used and I'd simply like these buttons to also do this in my program's browser.

    Thanks

  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    9,113

    Re: How to recognize mouse buttons 4-5 clicks on webbrowser control?

    No, my mouse has 4 buttons. The 4th button clicked once puts you at the previous page and the next click
    returns you back to the page you left on your 1st click.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2010
    Posts
    159

    Re: How to recognize mouse buttons 4-5 clicks on webbrowser control?

    Is it an old mouse? All the ones I saw in the last 10 years or so have 5 buttons.

  8. #8
    PowerPoster
    Join Date
    Jan 2008
    Posts
    9,113

    Re: How to recognize mouse buttons 4-5 clicks on webbrowser control?

    My computer is old too, more than 10 years
    Last edited by jmsrickland; May 6th, 2012 at 05:17 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  9. #9
    PowerPoster
    Join Date
    Jan 2008
    Posts
    9,113

    Re: How to recognize mouse buttons 4-5 clicks on webbrowser control?

    I don't know if this is going to be of any help and I kind of think it won't but you might try using

    Code:
    Private Declare Function GetAsyncKeyState Lib "user32"(ByVal vKey As Long) As Integer
    vKey = 1 for Left click
    vKey = 2 for Right click
    vKey = 4 for Scroll wheel
    vKey = 5 for the Toggle button

    The problem with using this API is that it will detect any key pressed anywhere and that means anywhere. You know that there are no mouse events for the WebBrowser control so you would have to set up a timer event that detects the key but here the problem is how to know if the key or mouse button was pressed over the browser window.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  10. #10
    PowerPoster
    Join Date
    Jan 2008
    Posts
    9,113

    Re: How to recognize mouse buttons 4-5 clicks on webbrowser control?

    Somewhere there is a program that tells you where the mouse is at any time. Example; as you move the mouse around the Form and over controls a message at the top of the Form tells you that the mouse is over a textbox, or it is over command button, or listview, etc, etc. I don't know where this VB program is but I remember seeing it either here or some other programming forum. You need to find this program and get it's code for detecting the location of the mouse.

    Let's say you are lucky and you have found it then you can do something like this

    My mouse only has 4 buttons so I do not know the VKey for the 5th button

    Code:
      '
      '
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal VKey As Long) As Integer
      '
      '
    Private Sub WebBrowser1_MouseDown(Button As Integer)
     Select Case Button
       Case 1
         Label1 = "Left Click"
       Case 2
         Label1 = "Right Click"
       Case 4
         Label1 = "Scroll Wheel"
       Case 5
         Label1 = "Toggle Button"
     End Select
    End Sub
    
    Private Sub Timer1_Timer()
     Dim VKey As Integer 
     
     Timer1.Enabled = False
     
     '
     ' Put the code to determine where the mouse is here. If the code detects that the mouse is over
     ' the WebBrowser then set MouseOverWebbrowser = True 
     '
     If MouseOverWebbrowser Then
       For VKey = 1 To 5
         If GetAsyncKeyState(VKey) Then
           WebBrowser1_MouseDown VKey
           Exit For
         End If
       Next VKey
     End If
     Timer1.Enabled = True
    End Sub
      '
      '
    Also, here is a link I found that may be of some help:


    http://www.vbaccelerator.com/home/VB...ks/article.asp
    Last edited by jmsrickland; May 6th, 2012 at 08:37 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.