public void OnTextInputPreviewKeyDown(Key key) { if (key != Key.Enter) { return; } var(textInputCommand, userEnteredText) = TextInputParser.ParseText(TextInput); TextInput = ""; OnPropertyChanged(nameof(TextInput)); UserInputReceived?.Invoke( this, new TextInputCommandEventArgs(textInputCommand, userEnteredText)); }
public void Initialize( ) { var document = Builtins.Global["document"]; body = (document.getElementsByTagName("body"))[0]; div = document.getElementById("div1"); body.addEventListener("keydown", new Action <dynamic>(e => { //Builtins.Global[ "alert" ]( 123 ); e.preventDefault( ); })); bool mousePressed = false; body.addEventListener("mousedown", new Action <dynamic>(e => { dynamic pos = Builtins.Global["getRelativePos"](e, div); int divWidth = div.offsetWidth; int divHeight = div.offsetHeight; if (((int)pos.x) < divWidth && ((int)pos.y) < divHeight) { int coordX = pos.x / (divWidth * 1.0 / width); int coordY = pos.y / (divHeight * 1.0 / height); Builtins.Global["console"].log("mousedown " + pos.x + " " + pos.y + " -> " + coordX + " " + coordY); UserInputReceived.Invoke(this, new UserInputEventArgs( new INPUT_RECORD( ) { EventType = EventType.MOUSE_EVENT, MouseEvent = new MOUSE_EVENT_RECORD( ) { dwButtonState = MOUSE_BUTTON_STATE.FROM_LEFT_1ST_BUTTON_PRESSED, dwControlKeyState = 0, dwEventFlags = MouseEventFlags.PRESSED_OR_RELEASED, dwMousePosition = new COORD((short)coordX, (short)coordY) } })); } mousePressed = true; //e.preventDefault( ); })); body.addEventListener("mouseup", new Action <dynamic>(e => { dynamic pos = Builtins.Global["getRelativePos"](e, div); int divWidth = div.offsetWidth; int divHeight = div.offsetHeight; if (((int)pos.x) < divWidth && ((int)pos.y) < divHeight) { int coordX = pos.x / (divWidth * 1.0 / width); int coordY = pos.y / (divHeight * 1.0 / height); Builtins.Global["console"].log("mouseup: " + pos.x + " " + pos.y + " -> " + coordX + " " + coordY); UserInputReceived.Invoke(this, new UserInputEventArgs( new INPUT_RECORD() { EventType = EventType.MOUSE_EVENT, MouseEvent = new MOUSE_EVENT_RECORD() { dwButtonState = 0, dwControlKeyState = 0, dwEventFlags = MouseEventFlags.PRESSED_OR_RELEASED, dwMousePosition = new COORD((short)coordX, (short)coordY) } })); } mousePressed = false; //e.preventDefault( ); })); body.addEventListener("mousemove", new Action <dynamic>(e => { dynamic pos = Builtins.Global["getRelativePos"](e, div); int divWidth = div.offsetWidth; int divHeight = div.offsetHeight; if (((int)pos.x) < divWidth && ((int)pos.y) < divHeight) { int coordX = pos.x / (divWidth * 1.0 / width); int coordY = pos.y / (divHeight * 1.0 / height); // Builtins.Global["console"].log("mousemove " + pos.x + " " + pos.y + " -> " + coordX + " " + coordY); UserInputReceived.Invoke(this, new UserInputEventArgs( new INPUT_RECORD() { EventType = EventType.MOUSE_EVENT, MouseEvent = new MOUSE_EVENT_RECORD() { dwButtonState = mousePressed ? MOUSE_BUTTON_STATE.FROM_LEFT_1ST_BUTTON_PRESSED : 0, dwControlKeyState = 0, dwEventFlags = MouseEventFlags.MOUSE_MOVED, dwMousePosition = new COORD((short)coordX, (short)coordY) } })); } //e.preventDefault( ); })); initBuffer( ); //flushScreen( ); }