Quantcast
Channel: Questions in topic: "keyboard"
Viewing all articles
Browse latest Browse all 605

Can you simulate key press within WebView?

$
0
0
I'm not entirly skilled with code but im attempting to use WebView to move a game from browser to mobile. I have the game working and openeing fine, but I need to make UI buttons to siulate keyboard key presses. This is the code i currently have. I am unsure why but it does nothing. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.LowLevel; public class MouseSim : MonoBehaviour { public bool going; public KeyboardState currentDown; public KeyboardState currentUp; public Keyboard keyboard; public KeyboardState wDown = new KeyboardState(); public KeyboardState wUp = new KeyboardState(); void Start() { keyboard = InputSystem.AddDevice(); wDown.Press(Key.W); wUp.Release(Key.W); } //When button is pressed this is sent in by the button public void setKey(string key) { if (going) return; if (key == "w") { currentDown = wDown; currentUp = wUp; } } //When the button is pressed this is sent in after the setKey("w") public void setTime(float time) { if (going) return; StartCoroutine(KeyPress(time)); } IEnumerator KeyPress(float wait) { going = true; InputSystem.QueueStateEvent(keyboard, currentDown); yield return new WaitForSeconds((Random.Range(0f, (wait / 10f)) + wait)); InputSystem.QueueStateEvent(keyboard, currentUp); going = false; } } It is running through all of the functions (Checked with a Debug.Log) and has the values of float time = 1; string key = "w"; I'm unsure where to go from here and if anyone has any ideas of diffrent ways to simulate a key press or even to tell webview a key was pressed then Im open to ideas.

Viewing all articles
Browse latest Browse all 605

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>