gtkmouseeventocamllablgtk

Detecting a Ctrl+click event in lablgtk


This question explains how to detect a ctrl+click in pygtk.

Does it also work on Lablgtk? Or is there a simpler way to do it?


Solution

  • In lablgtk, there is a more direct solution, although it is not immediately obvious.

    From a mouse click event ev (of type GdkEvent.Button.t), you can detect events such as ctrl+click/shift+click with GdkEvent.Button.state and Gdk.Convert.modifier), as in the following example:

    let state = GdkEvent.Button.state ev in
    let modifiers = Gdk.Convert.modifier state in
    let button = GdkEvent.Button.button ev in
    if button = 1 && List.mem `CONTROL modifiers then
      (* Ctrl+left click *) ...
    else if button = 3 && List.mem `SHIFT` modifiers then
      (* Shift+right click *) ...
    

    The type of the modifier list is Gdk.Tags.modifier.