Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 106 additions & 81 deletions Assets/AltTester/AltServer/Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using UnityEngine.EventSystems;
using UnityEngine.InputSystem.UI;
using UnityEngine.Scripting;
using System.Runtime.InteropServices;

[Preserve]
public class Input : MonoBehaviour
Expand Down Expand Up @@ -1105,90 +1106,114 @@ internal static IEnumerator tapClickCoordinatesLifeCycle(UnityEngine.Vector2 scr
if (monoBehaviourTarget != null) monoBehaviourTarget.SendMessage("OnMouseExit", UnityEngine.SendMessageOptions.DontRequireReceiver);
}

internal static IEnumerator tapClickElementLifeCycle(UnityEngine.GameObject target, int count, float interval, bool tap)
{
UnityEngine.Vector3 screenPosition;
AltRunner._altRunner.FindCameraThatSeesObject(target, out screenPosition);
yield return new WaitForEndOfFrame();//run after Update
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool SetCursorPos(int x, int y);

var pointerEventData = new UnityEngine.EventSystems.PointerEventData(UnityEngine.EventSystems.EventSystem.current)
{
position = screenPosition,
button = UnityEngine.EventSystems.PointerEventData.InputButton.Left,
eligibleForClick = true,
pressPosition = screenPosition
};
mousePosition = screenPosition;
pointerEventData.pointerEnter = target;
//repeat
for (int i = 0; i < count; i++)
{
float time = 0;
AltRunner._altRunner.ShowClick(screenPosition);
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

/* pointer/touch down */
UnityEngine.Touch touch = new UnityEngine.Touch();
int pointerId = 0;
if (tap)
{
touch = createTouch(screenPosition);
pointerId = touch.fingerId;
}
pointerEventData.pointerId = pointerId;

var keyStructure = new KeyStructure(UnityEngine.KeyCode.Mouse0, 1.0f);//power 1
_keyCodesPressedDown.Add(keyStructure);
_keyCodesPressed.Add(keyStructure);
if (EventSystem.current.currentInputModule.GetType().Name != typeof(InputSystemUIInputModule).Name)
{
UnityEngine.EventSystems.ExecuteEvents.Execute(target, pointerEventData, UnityEngine.EventSystems.ExecuteEvents.initializePotentialDrag);

UnityEngine.EventSystems.ExecuteEvents.Execute(target, pointerEventData, UnityEngine.EventSystems.ExecuteEvents.pointerDownHandler);
}
if (target != null) target.SendMessage("OnMouseDown", UnityEngine.SendMessageOptions.DontRequireReceiver);
pointerEventData.pointerPress = target;

time += UnityEngine.Time.unscaledDeltaTime;
yield return null;
public const int MOUSEEVENTF_LEFTDOWN = 0x02;
public const int MOUSEEVENTF_LEFTUP = 0x04;

_keyCodesPressedDown.Remove(keyStructure);
beginKeyUpTouchEndedLifecycle(keyStructure, tap, ref touch);

if (EventSystem.current.currentInputModule.GetType().Name != typeof(InputSystemUIInputModule).Name)
{
UnityEngine.EventSystems.ExecuteEvents.Execute(target, pointerEventData, UnityEngine.EventSystems.ExecuteEvents.pointerUpHandler);
UnityEngine.EventSystems.ExecuteEvents.Execute(target, pointerEventData, UnityEngine.EventSystems.ExecuteEvents.pointerClickHandler);
}

if (target != null)
{
target.SendMessage("OnMouseUp", UnityEngine.SendMessageOptions.DontRequireReceiver);
target.SendMessage("OnMouseUpAsButton", UnityEngine.SendMessageOptions.DontRequireReceiver);
}

time += UnityEngine.Time.unscaledDeltaTime;
yield return null;

endKeyUpTouchEndedLifecycle(keyStructure, tap, touch);

if (i != count - 1 && time < interval)//do not wait at last click/tap
{
float elapsedTime = 0;
while (elapsedTime < interval - time)
{
elapsedTime += UnityEngine.Time.unscaledDeltaTime;
yield return null;
}
}
}
//This simulates a left mouse click
public static void LeftMouseClick(int xpos, int ypos)
{
SetCursorPos(xpos, ypos);
mouse_event(MOUSEEVENTF_LEFTDOWN, xpos, ypos, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, xpos, ypos, 0, 0);
}

// mouse position doesn't change but we fire on mouse exit
if (EventSystem.current.currentInputModule.GetType().Name != typeof(InputSystemUIInputModule).Name)
{
UnityEngine.EventSystems.ExecuteEvents.Execute(target, pointerEventData, UnityEngine.EventSystems.ExecuteEvents.pointerExitHandler);
}
if (target != null)
target.SendMessage("OnMouseExit", UnityEngine.SendMessageOptions.DontRequireReceiver);
internal static IEnumerator tapClickElementLifeCycle(UnityEngine.GameObject target, int count, float interval, bool tap)
{
UnityEngine.Debug.Log("1");
UnityEngine.Debug.Log("posx: " + (int)target.transform.position.x);
UnityEngine.Debug.Log("posy: " + (int)target.transform.position.y);
LeftMouseClick(810, 390);
UnityEngine.Debug.Log("2");
return null;
// yield return new WaitForEndOfFrame();
// UnityEngine.Vector3 screenPosition;
// AltRunner._altRunner.FindCameraThatSeesObject(target, out screenPosition);
// yield return new WaitForEndOfFrame();//run after Update

// var pointerEventData = new UnityEngine.EventSystems.PointerEventData(UnityEngine.EventSystems.EventSystem.current)
// {
// position = screenPosition,
// button = UnityEngine.EventSystems.PointerEventData.InputButton.Left,
// eligibleForClick = true,
// pressPosition = screenPosition
// };
// mousePosition = screenPosition;
// pointerEventData.pointerEnter = target;
// //repeat
// for (int i = 0; i < count; i++)
// {
// float time = 0;
// AltRunner._altRunner.ShowClick(screenPosition);

// /* pointer/touch down */
// UnityEngine.Touch touch = new UnityEngine.Touch();
// int pointerId = 0;
// if (tap)
// {
// touch = createTouch(screenPosition);
// pointerId = touch.fingerId;
// }
// pointerEventData.pointerId = pointerId;

// var keyStructure = new KeyStructure(UnityEngine.KeyCode.Mouse0, 1.0f);//power 1
// _keyCodesPressedDown.Add(keyStructure);
// _keyCodesPressed.Add(keyStructure);
// if (EventSystem.current.currentInputModule.GetType().Name != typeof(InputSystemUIInputModule).Name)
// {
// UnityEngine.EventSystems.ExecuteEvents.Execute(target, pointerEventData, UnityEngine.EventSystems.ExecuteEvents.initializePotentialDrag);

// UnityEngine.EventSystems.ExecuteEvents.Execute(target, pointerEventData, UnityEngine.EventSystems.ExecuteEvents.pointerDownHandler);
// }
// if (target != null) target.SendMessage("OnMouseDown", UnityEngine.SendMessageOptions.DontRequireReceiver);
// pointerEventData.pointerPress = target;

// time += UnityEngine.Time.unscaledDeltaTime;
// yield return null;

// _keyCodesPressedDown.Remove(keyStructure);
// beginKeyUpTouchEndedLifecycle(keyStructure, tap, ref touch);

// if (EventSystem.current.currentInputModule.GetType().Name != typeof(InputSystemUIInputModule).Name)
// {
// UnityEngine.EventSystems.ExecuteEvents.Execute(target, pointerEventData, UnityEngine.EventSystems.ExecuteEvents.pointerUpHandler);
// UnityEngine.EventSystems.ExecuteEvents.Execute(target, pointerEventData, UnityEngine.EventSystems.ExecuteEvents.pointerClickHandler);
// }

// if (target != null)
// {
// target.SendMessage("OnMouseUp", UnityEngine.SendMessageOptions.DontRequireReceiver);
// target.SendMessage("OnMouseUpAsButton", UnityEngine.SendMessageOptions.DontRequireReceiver);
// }

// time += UnityEngine.Time.unscaledDeltaTime;
// yield return null;

// endKeyUpTouchEndedLifecycle(keyStructure, tap, touch);

// if (i != count - 1 && time < interval)//do not wait at last click/tap
// {
// float elapsedTime = 0;
// while (elapsedTime < interval - time)
// {
// elapsedTime += UnityEngine.Time.unscaledDeltaTime;
// yield return null;
// }
// }
// }

// // mouse position doesn't change but we fire on mouse exit
// if (EventSystem.current.currentInputModule.GetType().Name != typeof(InputSystemUIInputModule).Name)
// {
// UnityEngine.EventSystems.ExecuteEvents.Execute(target, pointerEventData, UnityEngine.EventSystems.ExecuteEvents.pointerExitHandler);
// }
// if (target != null)
// target.SendMessage("OnMouseExit", UnityEngine.SendMessageOptions.DontRequireReceiver);
}

private static void updateTouchInTouchList(Touch touch)
Expand Down Expand Up @@ -1553,7 +1578,7 @@ public override string ToString()
}
}
#else
using UnityEngine;
using UnityEngine;

namespace Altom.AltTester.InputModule
{
Expand Down
16 changes: 8 additions & 8 deletions Assets/AltTester/AltServer/InputController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ public static void ClickElement(UnityEngine.GameObject target, int count, float
{
#if ALTTESTER
List<IEnumerator> coroutines = new List<IEnumerator>();
#if ENABLE_INPUT_SYSTEM
coroutines.Add(NewInputSystem.ClickElementLifeCycle(target, count, interval));
#endif
#if ENABLE_LEGACY_INPUT_MANAGER
// #if ENABLE_INPUT_SYSTEM
// coroutines.Add(NewInputSystem.ClickElementLifeCycle(target, count, interval));
// #endif
// #if ENABLE_LEGACY_INPUT_MANAGER
coroutines.Add(Input.tapClickElementLifeCycle(target, count, interval, false));
#endif
AltRunner._altRunner.StartCoroutine(runThrowingIterator(coroutines, onFinish));
#else
throw new AltInputModuleException(AltErrors.errorInputModule);
// #endif
// AltRunner._altRunner.StartCoroutine(runThrowingIterator(coroutines, onFinish));
// #else
// throw new AltInputModuleException(AltErrors.errorInputModule);
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ public void TestPressKeyWaitTheDuration()
public void TestClickElement()
{
const string name = "Capsule";
var altElement = altDriver.FindObject(By.NAME, name).Tap();
var altElement = altDriver.FindObject(By.NAME, name).Click();
Assert.AreEqual(name, altElement.name);
// altDriver.WaitForObjectWithText(By.NAME, "CapsuleInfo", "Capsule was clicked to jump!");
altDriver.WaitForObject(By.PATH, "//CapsuleInfo[@text=Capsule was clicked to jump!]");
Expand Down