Add OnKeyDown and OnKeyUp event for API

This commit is contained in:
Sardelka 2022-07-11 11:06:57 +08:00
parent cda3d37f37
commit b1d67bd1c4
2 changed files with 16 additions and 9 deletions

View File

@ -82,6 +82,8 @@ namespace RageCoop.Client
Tick += OnTick; Tick += OnTick;
Tick += (s,e) => { Scripting.API.Events.InvokeTick(); }; Tick += (s,e) => { Scripting.API.Events.InvokeTick(); };
KeyDown += OnKeyDown; KeyDown += OnKeyDown;
KeyDown+=(s, e) => { Scripting.API.Events.InvokeKeyDown(s, e); };
KeyUp+=(s, e) => { Scripting.API.Events.InvokeKeyUp(s, e); };
Aborted += (object sender, EventArgs e) => CleanUp(); Aborted += (object sender, EventArgs e) => CleanUp();
Util.NativeMemory(); Util.NativeMemory();

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System; using System;
using System.Linq; using System.Linq;
using RageCoop.Core; using RageCoop.Core;
using System.Windows.Forms;
using GTA; using GTA;
namespace RageCoop.Client.Scripting namespace RageCoop.Client.Scripting
@ -117,6 +118,15 @@ namespace RageCoop.Client.Scripting
/// </summary> /// </summary>
public static event EmptyEvent OnTick; public static event EmptyEvent OnTick;
/// <summary>
/// This is equivalent of <see cref="Script.KeyDown"/>
/// </summary>
public static KeyEventHandler OnKeyDown;
/// <summary>
/// This is equivalent of <see cref="Script.KeyUp"/>
/// </summary>
public static KeyEventHandler OnKeyUp;
#region INVOKE #region INVOKE
internal static void InvokeVehicleSpawned(SyncedVehicle v) { OnVehicleSpawned?.Invoke(null, v); } internal static void InvokeVehicleSpawned(SyncedVehicle v) { OnVehicleSpawned?.Invoke(null, v); }
@ -126,6 +136,10 @@ namespace RageCoop.Client.Scripting
internal static void InvokePlayerDied() { OnPlayerDied?.Invoke(); } internal static void InvokePlayerDied() { OnPlayerDied?.Invoke(); }
internal static void InvokeTick() { OnTick?.Invoke(); } internal static void InvokeTick() { OnTick?.Invoke(); }
internal static void InvokeKeyDown(object s,KeyEventArgs e) { OnKeyDown?.Invoke(s,e); }
internal static void InvokeKeyUp(object s, KeyEventArgs e) { OnKeyUp?.Invoke(s, e); }
internal static void InvokeCustomEventReceived(Packets.CustomEvent p) internal static void InvokeCustomEventReceived(Packets.CustomEvent p)
{ {
var args = new CustomEventReceivedArgs() { Hash=p.Hash, Args=p.Args}; var args = new CustomEventReceivedArgs() { Hash=p.Hash, Args=p.Args};
@ -139,15 +153,6 @@ namespace RageCoop.Client.Scripting
} }
} }
#endregion #endregion
internal static void ClearHandlers()
{
OnPlayerDied=null;
OnTick=null;
OnPedDeleted=null;
OnPedSpawned=null;
OnVehicleDeleted=null;
OnVehicleSpawned=null;
}
} }
#region FUNCTIONS #region FUNCTIONS