- Home /
How to simulate a keypress in an onclick button on mobile(android/ios)???
I want to simulate a keyboard key press(ex: R key/Reload) in a button click event on a mobile device(android/ios)? Any one know how to pull of such things??! thanks in advanced
Using UIButton.OnClick() or UIButton.Events.Onclick() something
public UnityEvent myUI_Event; // Drag drop UI Button here
// Then call
myUI_Event.Invoke();
can you give me an example? Let's say: i create a button, and i want to call a "R" key (for reload) from that button's onClick event listener, how would i do that?
Answer by jim3878 · Jun 05, 2018 at 10:47 AM
PressEvent
if you want trigger Event by "PRESS" Button ,I suggest replacing Button with EventTrigger OnClick will invoke only if mouse is Up
just extends EventTrigger and override OnPointerDown
public override void OnPointerDown(PointerEventData data)
{
Debug.Log("OnPointerDown called.");
}
Simulate keyboard event
this page provide answer for Simulate Keyboard on C# but in my mind ,I'd rather use this
public override void OnPointerClick(PointerEventData data)
{
Reload();
}
hope it will help you
Your answer
Follow this Question
Related Questions
How to make floating mobile keyboard in mobile game ? 0 Answers
TouchScreenKeyboard flickers 0 Answers
Default Android Keyboard. 0 Answers
Touch joystick tutorials ? 0 Answers
Android Hardware Keyboard 0 Answers