Input Manager, detect any key....

Hi!, is there a way to know any key that an user has pressed?

like a scanf :S

thanks for any help! :smile:

Input.inputString

Daniel, thanks.

I think I was wrong, and I’ll ask the question better :stuck_out_tongue:

I need is to capture the keycodes of any key pressed.

For example if i press Button 0 on any joystick then I need to get JoystickButton0

Again, sorry for asking a wrong question :S

The unity input model works reversed of what you’re hinting at. Check out

file:///Applications/Unity/Documentation/ScriptReference/Input.html

for reference. Usually in a game you know which key you’re looking for, so you’d do that by running GetButton / GetButtonUp / GetButtonDown checks. Perhaps if you explain what it is you’re trying to do, we could be of further assistance?

if (Input.anyKeyDown)
{
    keyPressed = Input.inputString;
}

Is that what you are looking for?

-Jeremy

1 Like

He’s trying to code a key bindings screen, there’s not game config screen for webplayer builds so we need to script one ourselves to allow players to change their input configuration.

Getting the keycode is the easy part of the problem, but after we find the key the user pressed how do we assign it to the InputManager? Can’t find anything about this is the docs.

Kind of that Jeremy, But, if i press for example F1, keyPressed will be filled with “”.

On the other hand, Angryhat.

I’m trying to make my own custom Input manager, so we dont need to use the Input window to bind the custom keys that all the unity apps have when you start them.

If I’m not clearly enough please tell me and i’ll try to explain myself better.

I speak Spanish! :smile: srry for my bad english :wink:

Ah ok, I didn’t read your post carefully enough either.

There is no nice built-in way to do this, so you would have to check for every possible button I am afraid.

Might be worth wish listing this.

EDIT: Also, to bind input controls from your own interface, you basically have to write your own input manager and forget Unity’s altogether, as Unity’s input manager doesn’t currently support messing with the settings from code.

-Jeremy

Jeremy, that was that i was thinking i’ll have to do…

Currently I’m writing one at the moment.

thanks for the help! :smile:

If you want, i did the hard work for you…

http://forum.unity3d.com/viewtopic.php?t=57501&postdays=0&postorder=asc&start=0

A custom inputmanager, easy to use :wink: cheers

I’d think the need for this has probably dissipated some. Especially considering that the last post before yours was some two years ago. You think I’m on to something here? :wink:

Unless I’m missing something, I don’t necessarily agree that there’s no interest in something like this. In-game, on-the-fly custom keybindings are pretty important, even expected, these days. It just doesn’t cut it to have to exit/restart a game just to rebind some controls you’re not really feeling.

Hunting through the scripting reference, I do see a couple of things like Event.character, but I can’t for the life of me figure out how to access them properly, since they’re barely documented.

event = Event.current;

if(event.isKey){
   if(event.type == EventType.KeyDown){
      Debug.Log(event.keyCode);
   }
}

look at Event class
look at EventType class
look at KeyCode class

you have urself a an Event based thing :slight_smile:
this is to be done inside an OnGUI call.

(This is the only way to access input data during an Editor script as well)

Cheers! I tried a number of different permutations of those calls within OnGUI, but never quite managed to find the right one. :stuck_out_tongue:

sorry i revived a old post,i didnt checked date…

But if you want to find out how i did it, you can download my inputmanager and check the source, its free anyway…