[SOLVED] How do you get Mouse coordinates in gui script

So I have a gui script where I want to check if I am hovering over a node, but I am quite unsure of how to do this.

In my init function i acquire input focus, and I get input, but only keyboard input.

Here is how I try to get the mouse coordinates:

if action_id == nil then
    print("action.x: " .. action.x)
    print("action.y: " .. action.y)
 end

If you want to get mouse coordinate on mouse over,
just delete if condition,

print("action.x: " .. action.x)
print("action.y: " .. action.y)

If u want to check if mouse over node you can use

gui.pick_node(node,action.x, action.y)
3 Likes

@aep.stmik answer is correct. You should be getting mouse coordinates in your gui script. What happesn if you pprint(action) in on_input() while moving the mouse?

1 Like

The problem is on_input does not seem to be called at all when I move my mouse, just when I type keys that I already specified in the game.input_binding,
so when I do:

pprint(action)

Nothing happens when I hover the mouse, only when I type a key, and when I do so, this is what I get:

DEBUG:SCRIPT: 
{
  value = 1,
  repeated = false,
  released = false,
  pressed = false,
}

In order to get mouse/touch events you need to create a binding for MOUSE_BUTTON_1/MOUSE_BUTTON_LEFT. Once you have this input binding you’ll start receiving mouse/touch events.

It’s described in the Input manual but I see that two tooltips/help-callouts in the input manual overlap. @sicher, can we fix this?

1 Like

Thanks a lot that worked, it would be nice to have a more straightforward way of accessing mouse position than having to add mouse button events but this is just fine for now :slight_smile: