Announcement

Collapse
No announcement yet.

bCaptureInput, AddCaptureKey, and AddFocusIgnoreKey Explained

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    bCaptureInput, AddCaptureKey, and AddFocusIgnoreKey Explained

    For those of you having trouble figuring out bCaptureInput, AddCaptureKey, and AddFocusIgnoreKey, here is a detailed explanation of their use:

    bCaptureInput

    Setting this to true in the default properties of your class will send all input (mouse, keyboard, and game controller) to the Flash class/SWF, instead of the game. Setting it to false allows all input to go to the game instead.

    usage:

    bCaptureInput = true | false

    AddFocusIgnoreKey

    If you set bCaptureInput to true, you can exclude individual keys from being capture by the SWF file and instead allow them to pass through to the game using AddFocusIgnoreKey.

    usage:

    AddFocusIgnoreKey('W');

    AddCaptureKey

    If you set bCaptureInput to false, you can include individual keys to be captured by the SWF file, instead of allowing them to pass through to the game.

    usage:

    AddCaptureKey('W');

    Example List of Capturable Keys

    The following list should be used when capturing or ignoring keys:

    1...0
    A...Z
    F1...F12
    Up
    Down
    Left
    Right
    Spacebar
    Enter
    Escape
    BackSpace
    LeftControl
    RightControl
    LeftShift
    RightShift
    PageUp
    PageDown
    Home
    Insert
    Equals
    Minus
    Tab
    LeftAlt
    RightAlt

    In Kismet, however, when using the Set GFx Captured Keys node, you may need to use the spelled out names of numbers, instead of the digits:

    one
    two
    three
    four
    five
    six
    seven
    eight
    nine
    zero

    Intercepting Input in ActionScript


    Once you are capturing a key(s) via UnrealScript or Kismet, you can listen for those keys in ActionScript with the following code:

    ActionScript 2.0 Code

    Code:
    import flash.external.ExternalInterface;
    
    var keyboardInput:Object = new Object(); // creates a new object to hold keyboard input.
    Key.addListener(keyboardInput); // uses the object to listen for keyboard input.
    
    /* when a key is pressed, execute this function. */
    keyboardInput.onKeyDown = function() 
    {
        /* store the keyboard input ASCII code inside 'keyPressed'. */
        var keyPressed:Number = Key.getCode();
        trace("Key Pressed" + keyPressed);
    
        /* Call the UnrealScript function 'KeyPressed' and send it the 'keyPressed' value. */
        ExternalInterface.call("KeyPressed", keyPressed);
    }
    The code stored in keyPressed is an ASCII value. Look up ASCII values on Google to get a complete listing.

    NOTE: The preferred path for keyboard input is usually going to be binding keys to functions in the DefaultInput.ini file. Then these UnrealScript functions can tell Flash movie clips what to do. There are, however, some situations where you'll want specific keys at specific times to go to the Flash file instead.

    #2
    I set bCaptureInput=true in my defaultproperties, but in an online game the mouse input is still being read by the game as well as the flash movie. Clicking on buttons on the flash movie will also, at the same time, aim and fire the gun.

    How can I turn this off?

    Comment


      #3
      Xyx maybe try bIgnoreMouseInput = true

      Comment


        #4
        Already tried that, no visible difference.

        I also tried bAllowFocus=false (default is true) just in case. Also no difference.

        Comment


          #5
          I don't know why it isn't working for you, without seeing your code. I can confirm that it works on my end though. As for clicking on buttons and the gun still firing, see this post:

          http://forums.epicgames.com/showthread.php?t=756070

          Comment


            #6
            Based on what you wrote, is it not possible to add Escape as a capture key?

            Comment


              #7
              I'm sure it can be added:

              Escape

              Comment


                #8
                Problem solved. I was running a separate mouse cursor movie that had bCaptureInput=false. I guess the mouse movie was still sending input to the game despite the other movie also being open.

                Comment


                  #9
                  Another observation... FocusIgnoreKeys have to be added to both the dialog movie and the mouse movie, or they'll still get captured.

                  Comment


                    #10
                    I put bCaptureInput to true but it doesn't seems works with Scaleform 4 so I'm supposed to use AddCaptureKey for each key I want (all in fact) ?

                    Another issue: can I capture the punctuation keys like "!", "?", ":", etc ?

                    Comment


                      #11
                      Yes you can. I have done exactly that. You can pull it off shorthand with something like the following.

                      Note that it is not expecting Strings, but names. Names are single quoted in text and cast with the name function.

                      Code:
                          local byte ndx;
                          for (ndx = 32; ndx < 128; ndx ++)   
                          {        
                              AddCaptureKey(name(chr(ndx)));    
                          }    
                          
                          AddCaptureKey('Up');
                          AddCaptureKey('Down');    
                          AddCaptureKey('Left');    
                          AddCaptureKey('Right');    
                          AddCaptureKey('BackSpace');    
                          AddCaptureKey('Spacebar');    
                          AddCaptureKey('Tab');

                      Comment


                        #12
                        Thanks for your code, it removes many lines, but the ponctuation keys still don't work.

                        Another question, it is possible to know if the shift key is pressed in order to make some combinaisons ? I tried KeyboardEvent.shiftKey, it always returns false.

                        Comment


                          #13
                          AddCaptureKey can be used to capture shift presses. (LeftShift & RightShift). You'll then need to figure out a way to use DefaultInput.ini in conjunction with UnrealScript to bind those keys to work as a modifier to other keys when pressed. But that is not a Scaleform specific problem to solve.

                          Comment


                            #14
                            Is there a way to temporarily toggle bCaptureInput? I have a situation in which I need to let Unreal to hear some input during a portion of a scaleform menu. Simply setting it true/false at runtime doesn't seem to have an effect.

                            Comment


                              #15
                              What if I want everything except the right thumbstick of an Xbox gamepad to be captured? I'd like the player to be able to rotate the camera around an actor in the gameworld while capturing all other input for my inventory screen.

                              Comment

                              Working...
                              X