User Tools

Site Tools


Responding to mouse double-clicks

by Richard Russell, October 2015

By default the ON MOUSE event interrupt is activated by clicking one of the mouse buttons, but a double-click is not distinguishable from a single click. If you specifically want to respond to mouse double-clicks two steps are necessary; firstly you must enable them as follows:

        SYS "GetClassLong", @hwnd%, GCL_STYLE TO wc%
        SYS "SetClassLong", @hwnd%, GCL_STYLE, wc% OR CS_DBLCLKS

This code should be executed just once during the initialisation phase of your program (use the Windows Constants utility to add declarations for the GCL_STYLE and CS_DBLCLKS constants in the usual way).

Secondly, you need to modify your ON MOUSE event handler to examine the @msg% system variable in order to discover whether the interrupt was caused by a single or double click. @msg% will have one of the following values:

Left button click
Middle button click
Right button click
Left button double-click
Middle button double-click
Right button double-click

There are various different approaches that may be adopted, but a simple asynchronous (polling) method is as follows:

        REM. During initialisation:
        DIM Mouse%(2), mous%(2)
        ON MOUSE Mouse%() = @msg%, @wparam%, @lparam% : RETURN
        REM. In your main 'polling loop':
        mous%() = 0
        SWAP mous%(), Mouse%()

On receiving a mouse click mous%(0) will contain the @msg% value, mous%(1) will contain the @wparam% value (which contains information on whether the Shift and/or Control keys were pressed) and mous%(2) will contain the @lparam% value (which contains information on the position of the mouse when it was clicked). See the description of ON MOUSE in the main Help documentation for more details.

If you prefer to use a synchronous method you can call a procedure when the interrupt occurs, as follows:

        ON MOUSE PROCmouse(@msg%, @wparam%, @lparam%) : RETURN

Note that when the user double-clicks the mouse you may well receive a 'single click' interrupt as well, and your program will need to cope with that.

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information
responding_20to_20mouse_20double-clicks.txt · Last modified: 2018/04/16 14:31 by richardrussell