Check modifier keys during drag & drop


Is it possible to check that the left or right Shift key is pressed when dragging a file onto a GLFW window?

I’ve tried the following but unsurprisingly it didn’t work (because Shift wasn’t pressed in the GLFW window):

const bool shift_pressed =
    glfwGetKey(get_window(), GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS ||
    glfwGetKey(get_window(), GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS;

I suspect that the answer is that what I’m asking isn’t possible, but I hope to be wrong!

Thanks for a great library.

Try setting the window focus with glfwFocusWindow(window); in your drop callback, then checking the state. I just did a quick test and this seemed to work for me.

What works is the following workflow:

  1. GLFW window is in focus.
  2. User presses Shift, then drags & drops a file onto the window.

In this case, shift_pressed is true, even without adding


What doesn’t work sadly is this:

  1. User switches focus to another window (typically, Windows Explorer).
  2. User drags & drops file onto GLFW window (which isn’t in focus).

In this case, shift_pressed is false, even with the glfwFocusWindow() call.

I think the only way that latter workflow can work is by checking the keyboard status at the time of the file drop (and not relying on the key cache).