Detect Ctrl key pressed during drop


I’m adding Drag’n’Drop support for a Gtk program, and I want to change the drop operation when my program receives it depending on whether the user has the Ctrl key pressed or not. Is it possible to detect that key pressed during the drag-data-received event? Maybe in other event? How?


When implementing drag and drop support in your application you should always check the GdkDragAction, e.g. COPY, MOVE, or ASK, on the GdkDragContext instance you’re given by GTK.

If you’re handling the dragging from your own process, you can set that action depending on the modifiers mask by connecting to the drag-motion signal. There’s an example in the gtk_drag_dest_set() function.

1 Like

Well, I tried that example, both with the deprecated get_pointer() and with the new get_device_position(), but in both cases I always receive 0 in the mask, no matter if I press Ctrl, Shift… But this is with Wayland; with X11 the mask value changes as expected (although Ctrl doesn’t work: the drag-motion signal is not emitted if Ctrl is pressed. Should I report a bug in Gtk/Gdk?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.