godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Getting global key input #7713

Closed MudkipWorld closed 1 year ago

MudkipWorld commented 1 year ago

Describe the project you are working on

Working on a PNGTuber/ Vtuber app along with a desktop pet/ mascot app.

Describe the problem or limitation you are having in your project

Unable to get the global key capture through GDScript. I can only find getting the position of the mouse, but nothing related to pressed keys. Which means I am unable to get my software working while unfocused in any way; in the background, minimized, mouse pressed somewhere else,....

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Adding a get_global_key_input() for example. It will be detecting a specific key.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Example : if get_global_key_input("ui_left").pressed:

Do something here

If this enhancement will not be used often, can it be worked around with a few lines of script?

Sadly I have done a ton of searching and going on different sites and resources, this feature can't be done normally as far as I am aware. At least not with GDScript from what I know.

Is there a reason why this should be core and not an add-on in the asset library?

I have seen this feature asked about so many times and I person would use it alot. I have seen different software with godot popping around where they mentioned not being able to achieve this due to it not being that possible or hard to find work around.

Not sure if I am allowed to link examples (since they aren't mine), but if needed, tell me!

AThousandShips commented 1 year ago

I'm unsure how possible this is, might be complicated to get keys when app is not focused

MudkipWorld commented 1 year ago

I'm unsure how possible this is, might be complicated to get keys when app is not focused

I have seen apps made with Unity (away from the whole recent mess) back then that did have this functionality. Complicated? I agree, it might not be the easiest thing to add. Impossible? I don't think so personally, since as stated, other engines were able to do it and heads up, the "get_global_mouse_posistion()" does work when the window isn't focused.

Calinou commented 1 year ago

Thanks for the proposal! Consolidating in https://github.com/godotengine/godot-proposals/issues/1919.

I'm unsure how possible this is, might be complicated to get keys when app is not focused

This is definitely feasible on a technical level, but only on desktop platforms. Linux + Wayland setups may also have trouble with this, as Wayland doesn't allow global shortcuts as part of its security model (at least by default).

MudkipWorld commented 1 year ago

Thanks for the proposal! Consolidating in #1919.

I'm unsure how possible this is, might be complicated to get keys when app is not focused

This is definitely feasible on a technical level, but only on desktop platforms. Linux + Wayland setups may also have trouble with this, as Wayland doesn't allow global shortcuts as part of its security model (at least by default).

Gotcha!, from my understanding from the linked issue, I would need to use C# in this case, correct?

Calinou commented 1 year ago

Gotcha!, from my understanding from the linked issue, I would need to use C# in this case, correct?

Currently, you'd need to use C# interoperability with a native library or GDExtension to achieve this indeed.