1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

UE3 - UT3 Custom Key Input

Discussion in 'Programming' started by LegionofPhoenix, Oct 7, 2009.

  1. LegionofPhoenix

    LegionofPhoenix New Member

    Joined:
    Aug 28, 2009
    Messages:
    13
    Likes Received:
    0
    Hey, So I've searched countless forums and looked over many lines of code in an attempt to figure this out. That being said, it still stumps me.

    I have created a custom gametype. It works perfectly, no problems. I want to make a key run a console event. In kismet I'll just set that console event to the action I want to happen. So basically, instead of typing

    "ceRun" I want to press the key "P" so that it runs the console event "Run".

    If there is another way that you think would solve this problem, by all means suggest it. Such as creating a custom kismet block that runs, "When P is pressed do output>"

    Basically, creating custom keybindings for my custom gametype / prefix.

    The following it to help anyone searching the internet to find this thread.

    -------------------------------------------

    Custom Keybinding UT3 Unreal Tournament 3 Interaction UTPlayerController
     
  2. LegionofPhoenix

    LegionofPhoenix New Member

    Joined:
    Aug 28, 2009
    Messages:
    13
    Likes Received:
    0
    Tried this code from the UDN Wiki

    Code:
    class BWInteraction extends Interaction;
    
    
    function Initialized()
    {
       log(self@"has been initialized");
    }
    
    function PostRender( canvas Canvas )
    {
    }
    
    function bool KeyEvent( out EInputKey Key, out EInputAction Action, 
    
    FLOAT Delta )
    {
       local PlayerController PlayerOwner;
    
       if( Action!=IST_Press )
          return false;
       else if( Key==IK_P )
       {
          PlayerOwner = ViewportOwner.Actor;
          PlayerOwner.ClientMessage("P key has been pressed.");
          
          return true;
       }
       return false;
    }
    
    
    defaultproperties
    {
       bVisible=true
       bActive=true
       bNativeEvents=False
    }
    
    I get an error.

    Error, Unrecognized type 'EInputKey'
     
    Last edited by a moderator: Oct 9, 2009
  3. Phoenix_Wing

    Phoenix_Wing Official Kantham Stalker

    Joined:
    Mar 28, 2008
    Messages:
    386
    Likes Received:
    0
    That needs to be placed in a subclassed Interaction class.

    There is a better and easier way to do this though. Subclass the Input class, and add this code
    Code:
    function SetupMyStuff()
    {
       local int i;
       local KeyBind MyKeybind;
    
       for (i =0; i > Bindings.Length; i++)
       {
             //Make sure the bind doesn't already exist
    	 if (Bindings[i].Command == "MyExecFunction")
    	    return;
       }
    
       //Name of the Key to call the function
       MyKeybind.Name = 'G';
       //Exec function that will be called when key is pushed
       MyKeybind.Command = "MyConsoleCommand";
       //Assign the KeyBind 
       Bindings[Bindings.Length] = MyKeybind;
       //Save the Keybind to the UTInput.ini file
       SaveConfig();
    }
    
    Then attach it to the PlayerController class.

    EDIT: Or to save you a ton of time just open up your UTInput.ini and add a line that says this:
    Code:
    Bindings=(Name="MyKey",Command="MyConsoleCommand",Control=False,Shift=False,Alt=False)
    
     
    Last edited: Oct 7, 2009
  4. LegionofPhoenix

    LegionofPhoenix New Member

    Joined:
    Aug 28, 2009
    Messages:
    13
    Likes Received:
    0
    So I extended the "UTInput" class with the following

    Code:
    
    class BWInput extends Input;
    
    function SetupMyStuff()
    {
       local int i;
       local KeyBind MyKeybind;
    
       for (i =0; i > Bindings.Length; i++)
       {
             //Make sure the bind doesn't already exist
    	 if (Bindings[i].Command == "MyExecFunction")
    	    return;
       }
    
       //Name of the Key to call the function
       MyKeybind.Name = 'U';
       //Exec function that will be called when key is pushed
       MyKeybind.Command = "toggleWorld";
       //Assign the KeyBind 
       Bindings[Bindings.Length] = MyKeybind;
       //Save the Keybind to the UTInput.ini file
       SaveConfig();
    }
    
    You also said I need to attach this to the PlayerController class. I apologize, but I don't know what you mean by this.

    Also. I attempted the 2nd method by going into my UTInput class and just attaching the custom bind key code, but that doesn't seem to work. I added the code in two separate places within UTInput since that is what it seems it wants. Most likely one for game and one for engine.

    Code:
    Bindings=(Name="U",Command="toggleWorld",Control=False,Shift=False,Alt=False)
    I am trying to run an event in kismet off of the key that is attached to the console command. So I am using "New Event>Console Event" to do this. I am assuming this will work since I see no plausible reason why it wouldn't.
     
  5. Phoenix_Wing

    Phoenix_Wing Official Kantham Stalker

    Joined:
    Mar 28, 2008
    Messages:
    386
    Likes Received:
    0
    I am not sure if the function has to be declared in the Input class itself or something else. Need Wormbo to come help me here.

    That code up there will produce the Bindings=... stuff in the .ini

    I am just wondering what it actually calls and where... I will do some looking around and let you know if i find anything. Sorry for not being of more help
     
  6. LegionofPhoenix

    LegionofPhoenix New Member

    Joined:
    Aug 28, 2009
    Messages:
    13
    Likes Received:
    0
    Oh man, it's ok. I sincerely appreciate the fact that I'm getting help at all. And you've helped me far more than you think thus far.
     
  7. Wormbo

    Wormbo Administrator Staff Member

    Joined:
    Jun 4, 2001
    Messages:
    5,913
    Likes Received:
    36
  8. LegionofPhoenix

    LegionofPhoenix New Member

    Joined:
    Aug 28, 2009
    Messages:
    13
    Likes Received:
    0
    Anyone have any other ideas that may help me solve this problem?
     
  9. Phoenix_Wing

    Phoenix_Wing Official Kantham Stalker

    Joined:
    Mar 28, 2008
    Messages:
    386
    Likes Received:
    0
    It is possible, you could do it this way.. but it will take a lil bit more code

    Use the same Bindings code up there to make the KeyBind
    Code:
    function bool InputKey (int ControllerId, name Key, EInputEvent EventType, optional float AmountDepressed=1.f, optional bool bGamepad)
    {
        local int i;
    
        for (i = 0; i > Bindings.Length; i++)
        {
             if (Bindings[i].Command == "MyExecFunction")
             {
                 MyExecFunction();
                 break;
              }     
        }
    } 
    
    DefaultProperties
    {
        __OnReceivedNativeInputKey__Delegate=Default__ThisClass.InputKey
    }
    
    That is a bit of a hack for now, but its the only way i have found to really work since there is very little documentation on KeyBinds *cough* give us some UDN documents epic *cough*

    Hope this helps you

    EDIT: You will need to let the Bindings config stuff run through at least once, then play, otherwise it wont load the keybind

    Double EDIT: Need the __OnReceivedNativeInputKey__Delegate... stuff for some reason. Tried it without it and it was never called for some odd reason. Must have to assign it like above
     
    Last edited: Oct 12, 2009
  10. LegionofPhoenix

    LegionofPhoenix New Member

    Joined:
    Aug 28, 2009
    Messages:
    13
    Likes Received:
    0
    So it should be apparent by now I am no coder. Hence the following results.

    Code:
    class BWInput extends Input;
    
    
    function bool InputKey (int ControllerId, name Key, EInputEvent EventType, optional float AmountDepressed=1.f, optional bool bGamepad)
    {
        local int i;
    
        for (i = 0; i > Bindings.Length; i++)
        {
             if (Bindings[i].Command == "MyExecFunction")
             {
                 MyExecFunction();
                 break;
              }     
        }
    }
     
    
    
       MyKeybind.Name = 'U';
    
       MyKeybind.Command = "toggleWorld";
    
       Bindings[Bindings.Length] = MyKeybind;
    
       SaveConfig();
    }
    
    DefaultProperties
    {
        __OnReceivedNativeInputKey__Delegate=Default__ThisClass.InputKey
    }
    That being said. I do consider myself a critical analyst. My current error exist on line 20 with the string "MyKeybind".

    I'm sure it is trying to refer to something it has discovered doesn't exist. Do I have to create a "MyKeybind" file for it to reference?

    Also, I noticed that my open/close brackets aren't an even number. Just curious about that.

    I sincerely apologize for my inability to understand what is likely straightforward code.
     
  11. Phoenix_Wing

    Phoenix_Wing Official Kantham Stalker

    Joined:
    Mar 28, 2008
    Messages:
    386
    Likes Received:
    0
    I'd say still keep that SaveConfig code in the other function since InputKey would be called every time a key is pushed and would cause quite a lot of backup D:

    Also if you want to call an object, you need a reference to it. You were on the right track, but in the Unreal World you can use a syntax like this
    Code:
    var MyObjectClass (such as Actor) ANameForThisObject (not the class name, but what you want to call it)
    
    
    Now you have an object type, but Unreal doesnt know which one you are talking about. You have to tell it which one like this
    Code:
    
    NameForThisObject = AnotherReference;
    
    Hope this helps :3
     
  12. LegionofPhoenix

    LegionofPhoenix New Member

    Joined:
    Aug 28, 2009
    Messages:
    13
    Likes Received:
    0
    Horrible Code: Round 2+

    Code:
    class BWInput extends Input;
    
    var InputKey MyKeybind
    
    MyKeyBind = AnotherReference;
    
    function bool InputKey (int ControllerId, name Key, EInputEvent EventType, optional float AmountDepressed=1.f, optional bool bGamepad)
    {
        local int i;
    
        for (i = 0; i > Bindings.Length; i++)
        {
             if (Bindings[i].Command == "MyExecFunction")
             {
                 MyExecFunction();
    
      		 MyKeybind.Name = 'U';
    
      		 MyKeybind.Command = "toggleWorld";
    
       		Bindings[Bindings.Length] = MyKeybind;
    
       		SaveConfig();
    
                 break;
              }     
        }
     
    
    }
    
    
    DefaultProperties
    {
        __OnReceivedNativeInputKey__Delegate=Default__ThisClass.InputKey
    }
    
    Thoughts:

    I am highly confused by the ObjectClass and Referencing. Pretend I am in kindergarten, I don't know how to add, subtract ect.

    Would the ObjectClass be something like "InputKey"? And what am I referencing?

    I also doubt the SaveConfig is in the correct place. I figured the "for loop' was basically only running once so I put it in the 'if statement' but I doubt it is placed correctly.

    I feel like if it was explained to me in detail I could eventually grasp how this code functions.

    Thanks as usual.
     

Share This Page