How to wait for keypress before returning value to ActionScript (Key binding menu)?

I am making an keybinding menu and in ActionScript3 when click a button (GFxClikWidget, not kb or mouse button) I am calling an UnrealScript function GetKeyPress which returns GFxObject containing a String(AS_String). The GetKeyPress function should wait for a button press (kb/mouse btn), capture it and then return the name of the button that is pressed. (I’ve set bCaptureInput to false so I could capture key press in my PlayerInput class)

The thing I don’t know how to do is how to wait for a button to be pressed before returning the GFxObject containing a String with it’s name back to AS3?

In my PlayerImput class i can add to DefaultProperties “OnReceivedNativeInputKey=KeyInput” which executes KeyInput everytime a key is pressed, Then in KeyInput function I can set some variable with the name of the pressed button. Then i can access that variable in GetKeyPress function and return it to AS3. But how to wait in GetKeyPress function for the button press?

PS. I want to capture the pressed button with UnrealScript and then return it’s name to AS3 because if I capture the button press with AS3 it will be ASCII code which then I have to convert somehow to UDK button name.

Not sure if i understand correctly, but sounds like you already have it setup correctly.

In US you are capturing the name of the most recent button pressed. So then when GetKeyPress() gets called, you can return the last know pressed key to AS3.

Doesn’t sound like you need to ‘wait’. Just return the last know pressed key each time it’s called.

I may have misunderstood.

EDIT:
OK I figured out how to do the binding menu. It’s not how I wanted it originaly but it works.
Intead of making variable retVal in AS and expecting US to return pressed key to that variable i just set the button label to “Press any key” and sent void function call to US. Then in US function i set a bool property (class variable) named bPressed to true (by default it’s false). Then in another function named “bool FilterButtonInput” with which you can capture every keypress i check if the bPressed is set to true and if it is I set the button’s label to the button name that is pressed (this func captures the button name too). Then i set the bPressed to false again. Here is the code (I simplified (and changed) it a bit because actually I don’t have a button in AS3 but a list with custom renderer with button inside, so I replaced the stuff I do with setting a button’s label) :

AS:



button.addEventListener(ButtonEvent.CLICK, function():void
				{
                                        var btnLabel = button.label;
					button.label = "Press any key";	
					ExternalInterface.call("GetKeyPress", btnLabel);
				});


US:



var GFxClikWidget ASBtn;
var string ButtonLabel;
var bool bPressed;

...

function GetKeyPress(string BtnLabel)
{
	Self.ButtonLabel = BtnLabel;
	bPressed = true;
}

event bool FilterButtonInput(int ControllerId, name ButtonName, EInputEvent InputEvent)
{
	if(InputEvent == IE_Released && bPressed == true && ButtonName != 'Escape')
	{
		ASBtn.SetString("label", ButtonName);
		bPressed = false;
	}
	else if(InputEvent == IE_Released && bPressed == true && ButtonName == 'Escape')
	{
                ASBtn.SetString("label", ButtonLabel);
		bPressed = false;
	}
	return false;
}


It seems that I needed to explain better what I am trying to do.
In AS i have a GFXClik button that has event listener and when it’s pressed it executes



button.label = "Press any key";
var retVal:Object = {};
retVal = ExternalInterface.call("GetKeyPress", "btnName");
button.label = retval.btnName;
...


This is the US code



function GFxObject GetKeyPress(string BtnNameMember)
{
	local GFxObject RetVal;
	local ASValue BtnName;
	local string BtnNameFromEngine;

	CurrentPlayerController = ShooterGamePlayerController(class'WorldInfo'.static.GetWorldInfo().GetALocalPlayerController());
	BtnNameFromEngine = string(CurrentPlayerController.PressedKey);

	BtnName.Type = AS_String;
	BtnName.s = BtnNameFromEngine;

	RetVal = CreateObject("Object");
	RetVal.Set(BtnNameMember, BtnName);

	return RetVal;
}


This code gets the last pressed key and sends it to AS3. In my ShooterGamePlayerInput i have



function bool KeyInput(int ControllerId, name KeyName, EInputEvent IEvent, float AmountDepressed, optional bool bGamepad)
{
	if(IEvent == IE_Released)
	{
		`log("Keyname released: "$ KeyName);
		PressedKey = KeyName;
	}
	return(false);
}

DefaultProperties
{
	OnReceivedNativeInputKey=KeyInput
}


But the way the code works now it returns MouseLeftClick to AS3 because that was the key I used to click the GFxClik button. But what I need is to click the GFxClik button, the function GetKeyPress to wait for another key press and then send that key name back to AS3 (like in all games key binding menus, you click button then it says press key and waits for keypress and when you press some key the button label changes with that key name). So before


BtnNameFromEngine = string(CurrentPlayerController.PressedKey);

I need to wait and for another keypress and return that to AS3 because if I don’t wait it returns MouseLeftClick which is what I used to click the GfxClik button itself.

I know that if you use the GFxUDKFrontEnd system you will push a dialog that works as a hook and this dialog waits for keypress and when it recieves keypress it the dialog pops out and sends the pressed key somewhere but I don’t use the GFxUDKFrontEnd system and i don’t have push/pop dialog functionality.