-1

I have a Trust GXT-25 mouse and it has 4 buttons: left, right, back and next.

I can only catch left and right. How can I detect the remaining 2 more events in Delphi XE3?

NGLN
  • 43,011
  • 8
  • 105
  • 200
roll
  • 117
  • 7
  • 1
    See [this feature request](http://qc.embarcadero.com/wc/qcmain.aspx?d=1715) in QualityCentral. – NGLN Dec 20 '14 at 09:33

2 Answers2

6

Depending on how the mouse implements those buttons, you will have to either:

  1. handle the WM_XBUTTONDOWN and WM_XBUTTONUP messages directly, or the WM_APPCOMMAND message. Refer to MSDN for more details:

    About Mouse Input: XBUTTONs

    A Delphi implementation could be, by using an ApplicationEvents.OnMessage event handler:

    const
      {$EXTERNALSYM MK_XBUTTON1}
      MK_XBUTTON1 = $20;
      {$EXTERNALSYM MK_XBUTTON2}
      MK_XBUTTON2 = $40;
      {$EXTERNALSYM XBUTTON1}
      XBUTTON1 = $1;
      {$EXTERNALSYM XBUTTON2}
      XBUTTON2 = $2;
    
    procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    begin
      case Msg.message of
        WM_XBUTTONDOWN:
          case LoWord(Msg.wParam) of
            MK_XBUTTON1: { Handle Back };
            MK_XBUTTON2: { Handle Forward };
          end;
        WM_XBUTTONUP:
          case HiWord(Msg.wParam) of
            XBUTTON1: { Handle Back };
            XBUTTON2: { Handle Forward };
          end;
      end;
    end;
    
  2. use the Raw Input API to register your desired window to receive WM_INPUT messages for mouse input.

NGLN
  • 43,011
  • 8
  • 105
  • 200
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I put a showmessage function to FormMouseDown event but if it only shown when I click with left or right button. – roll Dec 19 '14 at 23:59
  • @roll That's because they're not standard mouse buttons. Windows doesn't acknowledge these buttons because of so. What if you have a mouse with 30 buttons? Do you think Windows knows what all those buttons do? It's up to how the manufacturer implemented them. You're going to need to catch Windows messages, the `OnMouseDown` event will not give you what you need, because it only acknowledges the standard mouse buttons. – Jerry Dodge Dec 20 '14 at 00:01
  • Ok, but how to do it? – roll Dec 20 '14 at 00:04
  • 1
    @roll By following the advise and links provided by Remy in his answer :-) – Jerry Dodge Dec 20 '14 at 00:05
  • The `OnMouseDown` event is only triggered for `WM_(L|M|R)BUTTONDOWN` messages, not for the `WM_XBUTTONDOWN` message. You will have to write your own message handler, or override the Form's `WndProc()`, to handle that message (assuming the mouse driver even uses that button in the first place). Same with `WM_INPUT`. – Remy Lebeau Dec 20 '14 at 04:27
  • 1
    (assuming the mouse driver even uses that *message* in the first place) – Remy Lebeau Dec 20 '14 at 04:33
0

Depending on the mouse driver it is even posible that pressing one of the special mouse buttons won't even generate any mouse event, but instead the driver may programatically send a keyboard command instead.

You are talking about back and next buttons. Does these buttons serve for back and forward navigation in your browser?

If they do then it is quite possible that the mouse drivers are generating keyboard equivalent shourtcuts for this which are (ALT+Left for Back and ALT+Right for Next).

So I recomend you try using the OnKeyDown and OnKeyUp events to see if that is the case.

SilverWarior
  • 7,372
  • 2
  • 16
  • 22
  • Not to mention, many user input devices have their own control panel which can change what different buttons do. For example, on my Microsoft keyboard, I could make the browser back/next buttons open cat pictures instead. – Jerry Dodge Dec 20 '14 at 21:31