# Getting the clicked node inside a GUI

**URL:** <https://forum.defold.com/t/getting-the-clicked-node-inside-a-gui/80126>\
**Category:** Questions\
**Created:** [March 24, 2025, 8:08pm UTC](https://forum.defold.com/t/getting-the-clicked-node-inside-a-gui/80126 "2025-03-24T20:08:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vallo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/vallo/32/39171_2.png) [@Vallo](https://forum.defold.com/u/Vallo)\
**Post date:** [March 24, 2025, 8:08pm UTC](https://forum.defold.com/t/getting-the-clicked-node-inside-a-gui/80126/1 "2025-03-24T20:08:47Z")

</div>

Hello everyone, I’m new to Defold, and this is my first post on this forum. In my first project, I’m trying to recreate a keyboard, which is a fundamental element of my game.

So, I created a GUI, added a “general” node, and inside it, I created a node for each key. Then, I created a GUI script to manage the keyboard (mainly, the script should allow the keys to send a message based on the pressed letter, just like a regular keyboard, in addition to handling key press animations).

 ![Screenshot](https://forum-defold-uploads.b-cdn.net/original/3X/d/3/d3ab8dfcdfbd396b6df8336690fa6761ce61be70.png)

The problem is that I’m not sure how to manage this in the most correct and efficient way. With `action.x` and `action.y`, I can get the click coordinates, but after checking the GUI functions, I couldn’t find one that allows me to get the node at those coordinates.

The `gui.pick_node` function might be helpful, but it requires the node ID as a parameter. To use it, I would have to loop through all the nodes in the GUI on every click, and that doesn’t seem like a good idea since the GUI will be clicked many times in quick succession.

Does anyone have any advice on this? Is using a GUI not the best option? Should I use simple game objects for each key instead? Or is there a simple and smart way to efficiently handle key clicks in the GUI?

Thanks!

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [March 25, 2025, 11:04pm UTC](https://forum.defold.com/t/getting-the-clicked-node-inside-a-gui/80126/2 "2025-03-25T23:04:22Z")

</div>

Welcome! Looping through all the characters and using gui.pick\_node() should be fine. I wouldn’t worry about the performance for so few nodes.

Another option could be to use a library to do it for you, like Druid (which is excellent for all sorts of UI functionality):

[https://github.com/Insality/druid](https://github.com/Insality/druid)

---

<div class="post-metadata">

**Author:** ![Vallo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/vallo/32/39171_2.png) [@Vallo](https://forum.defold.com/u/Vallo)\
**Post date:** [March 26, 2025, 6:07am UTC](https://forum.defold.com/t/getting-the-clicked-node-inside-a-gui/80126/3 "2025-03-26T06:07:32Z")

</div>

Ok, thanks a lot for the reply! 🙏
