How to get which key was pressed in blueprint

Hi all, how I can get which key was pressed using blueprint?

I known that you can use override function in widgets OnKeyDown and compare if it equal to specific key, but how I can get exactly which input key was pressed and displayed in Print string ?

Thank you guys!

I am not sure what you are asking but here is an answer hope it helps:
Inside of the player blueprint, and make a new blueprint (An input key), make it the key you want to be the key that the string notices. And attach the input blueprint to a print string and type in a message with whatever you want in it.

Hope this helps!
Happy game development!

Thanks for answer and merry Christmas!

I was asking to get key i pressed to text. If i pressed space bar i need to get it in text (key name), i need know which key has been pressed by player.

Thank you

Hi,

I found the solution, I just missed one node, may be was just tiered :slight_smile:

Thank you for you help!

3 Likes

Well, if that’s the case than I think you can still set up inputs for every key and then have them have different text strings for example:
You could set up the inputs for all your keys, and then set up print lines or print text to the input and make the text say something like (Key name) was pressed. It would take a while but it is the way that is the simplest. You could always attach an event or cast to a widget but that is a lot more time consuming and harder.
Hope that helps.

am I late? xD

1 Like

why not this?

your BP looks so complicated and I don’t get the point

3 Likes

I was in the process of doing an input buffer system in BP since I didn’t really see too much on it and ran across this post and used THIS post for a starting point actually.

Last edit I did on it:
And an

don’t mind the top right, I was just lazy and didn’t take it out and it reminded me of an old animation joke I saw about Australia.

sorry for the edits, i don’t really post here much haha

In the future, please only use code that is relevant to the question. It can really confuse beginners who think they might need all of this to preform the very simple task.

1 Like

please note that this method will not work after localization. I hit a wall with this solution, just a mere week prior to production release.

Japanese and Chinese localized builds have different “Key display names” than the rest of the world. German and Russian are like english, where

  • Space = Space
  • Backspace = Backspace
  • etc.

but for example getting the Spacebar value in Japanese version of “get display name” will result in スペースバー.

This method is therefore unusable for anything using a direct keyboard input. The proposed blueprint solution completely broke my hacking pc mini-game :smiley: As of the moment I am searching for a better solution, probably going to look in the direction of reading the key values directly.

edit: found the solution. It is to compare the key structure directly and not the string value (which was stupid of me, I assumed the keycode display names are same everywhere…)

image

1 Like

Good to know!
Please share your solution if you find any please :slight_smile: