-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Applications:
Unity 2018.2.6f1
PowerUI 2.5 (from the web-page)
Using Unity's NetStandard 2.0 (I had to remove Pico, Precompiler directories and modify ReflectionEmit.cs (add comment to second line => #define AbleToCompile) to get it work.
HTML:
<div id="console">
<p class="title">CONSOLE</p>
<ul id="console-content"></ul>
<input id="console-input" type="text" value="textConsoleCommand">
</div>
JavaScript:
document.getElementById("console-input").addEventListener("keyup", function(ev) {
console.log("Key = ")
console.log(ev.key)
console.log(ev.code)
console.log("test")
})
Result:
Key =
test
Stacktrace of ev.key
UnityEngine.Debug:Log(Object)
JavaScript.ConsoleOutput:Log(consoleMessageStyle, Object[]) (at Assets/Plugins/PowerUI/Source/JavaScript/Web APIs/Console/ConsoleOutput.cs:62)
JavaScript.console:log(consoleMessageStyle, Object[]) (at Assets/Plugins/PowerUI/Source/JavaScript/Web APIs/Console/WebConsole.cs:255)
JavaScript.console:log(Object[]) (at Assets/Plugins/PowerUI/Source/JavaScript/Web APIs/Console/WebConsole.cs:60)
System.Reflection.MethodBase:Invoke(Object, Object[])
Jint.Runtime.Interop.MethodInfoFunctionInstance:Invoke(JsValue, JsValue[]) (at Assets/Plugins/PowerUI/Source/JavaScript/Jint/Runtime/Interop/MethodInfoFunctionInstance.cs:135)
Jint.Runtime.Interop.MethodInfoFunctionInstance:Call(JsValue, JsValue[]) (at Assets/Plugins/PowerUI/Source/JavaScript/Jint/Runtime/Interop/MethodInfoFunctionInstance.cs:65)
Jint.Runtime.ExpressionInterpreter:EvaluateCallExpression(CallExpression) (at Assets/Plugins/PowerUI/Source/JavaScript/Jint/Runtime/ExpressionIntepreter.cs:886)
Jint.Engine:EvaluateExpression(Expression) (at Assets/Plugins/PowerUI/Source/JavaScript/Jint/Engine.cs:453)
Jint.Runtime.StatementInterpreter:ExecuteExpressionStatement(ExpressionStatement) (at Assets/Plugins/PowerUI/Source/JavaScript/Jint/Runtime/StatementInterpreter.cs:33)
Jint.Engine:ExecuteStatement(Statement) (at Assets/Plugins/PowerUI/Source/JavaScript/Jint/Engine.cs:391)
Jint.Runtime.StatementInterpreter:ExecuteStatement(Statement) (at Assets/Plugins/PowerUI/Source/JavaScript/Jint/Runtime/StatementInterpreter.cs:23)
Jint.Runtime.StatementInterpreter:ExecuteStatementList(IEnumerable`1) (at Assets/Plugins/PowerUI/Source/JavaScript/Jint/Runtime/StatementInterpreter.cs:425)
Jint.Runtime.StatementInterpreter:ExecuteBlockStatement(BlockStatement) (at Assets/Plugins/PowerUI/Source/JavaScript/Jint/Runtime/StatementInterpreter.cs:536)
Jint.Engine:ExecuteStatement(Statement) (at Assets/Plugins/PowerUI/Source/JavaScript/Jint/Engine.cs:373)
Jint.Native.Function.ScriptFunctionInstance:Call(JsValue, JsValue[]) (at Assets/Plugins/PowerUI/Source/JavaScript/Jint/Native/Function/ScriptFunctionInstance.cs:93)
PowerUI.JsEventListener:handleEvent(Event) (at Assets/Plugins/PowerUI/Source/JavaScript/addEventListener-Js.cs:79)
Dom.EventsSet:Run(Event, Boolean) (at Assets/Plugins/PowerUI/Source/Dom/Events/EventsSet.cs:72)
Dom.EventTarget:HandleLocalEvent(Event, Boolean) (at Assets/Plugins/PowerUI/Source/Dom/Events/EventTarget.cs:89)
PowerUI.HtmlElement:HandleLocalEvent(Event, Boolean) (at Assets/Plugins/PowerUI/Source/Engine/Element/Element-JavaScript.cs:46)
PowerUI.HtmlInputElement:HandleLocalEvent(Event, Boolean) (at Assets/Plugins/PowerUI/Source/Engine/Tags/input.cs:379)
Dom.EventTarget:dispatchEvent(Event) (at Assets/Plugins/PowerUI/Source/Dom/Events/EventTarget.cs:172)
PowerUI.Input:OnKeyPress(Boolean, Char, Int32) (at Assets/Plugins/PowerUI/Source/Engine/Input/Input.cs:312)
PowerUI.StandardUpdater:OnGUI() (at Assets/Plugins/PowerUI/Source/Engine/StandardUpdater.cs:44)
Expected result:
Key =
Enter
13
test
UPDATE 1
I tried to stringify the event object:
console.log(JSON.stringify(ev))
Result is:
{}
UPDATE 2
When I type normal characters from Alphabet, it works but not correct.
If I type 'A' it will show:
Key =
A
A
test
It sounds the key and code are representing same value.
The output from the stringify is still {}, it looks like there is problem with JSON or it does not pack Events.
Other symbols 'Enter', 'Backspace', 'Semi-colon' are represented by ' ' (empty) symbol.
UPDATE 3
After more debugging I went to the StandardUpdater to line 50.
PowerUI.Input.OnKeyPress(true,current.character,(int)current.keyCode);
I added debug above this line for current and it shows:
Debug.Log("Current:" + current.ToString());
Debug.Log("KeyCode" + current.keyCode);
Debug.Log("KeyCode(int)" + ((int)current.keyCode));
Debug.Log("Character" + current.character);
Current:Event:KeyDown Character:\0 Modifiers:None KeyCode:Return
KeyCodeReturn
KeyCode(int)13
Character
Update 4
In KeyboardEvent.cs
Are these lines:
/// <summary>The keycode as text.</summary>
public string code{
get{
return ""+character;
}
}
/// <summary>The keycode.</summary>
public string key{
get{
return ""+character;
}
}
It should be
/// <summary>The keycode.</summary>
public int code{
get{
return keyCode;
}
}
/// <summary>The character.</summary>
public string key{
get{
return ""+character;
}
}
I'm able to get real keyCode now. For me is it fixed. But I will leave still this issue open.
Update 5
Regard to lib.dom.d.ts is your code correct.
/** @deprecated */
char: string;
/** @deprecated */
readonly charCode: number;
readonly code: string;
readonly ctrlKey: boolean;
readonly key: string;
/** @deprecated */
readonly keyCode: number;
I'm very confused for now. Where developers can take numerical non-deprecated keyCode now?
Anyway if you are offering deprecated char, can you offer keyCode too? It will make things more simply. Thank you.
Update 7
Well, this is my bad. The keyCode is already exists. I did not notice that the UIEvent class is partial.