Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Intersect.Client.Core;
- using Intersect.Client.Framework.GenericClasses;
- using Intersect.Client.Plugins;
- using Intersect.Client.Plugins.Interfaces;
- using System;
- using System.Collections.Generic;
- namespace Client.Plugins.InputExample
- {
- class InputExample : ClientPluginEntry
- {
- /// <summary>
- /// Tracks key state changes during this frame.
- /// Value is true for key down, false for key up.
- /// </summary>
- private Dictionary<Keys, bool> _keyStatesChanged = new Dictionary<Keys, bool>();
- public override void OnStart(IClientPluginContext context)
- {
- Input.KeyDown += HandleKeyDown;
- Input.MouseDown += HandleKeyDown;
- Input.KeyUp += HandleKeyUp;
- Input.MouseUp += HandleKeyUp;
- context.Lifecycle.GameUpdate += Lifecycle_GameUpdate;
- }
- void HandleKeyDown(Keys key)
- {
- if (!_keyStatesChanged.ContainsKey(key))
- _keyStatesChanged.Add(key, true);
- }
- void HandleKeyUp(Keys key)
- {
- if (!_keyStatesChanged.ContainsKey(key))
- _keyStatesChanged.Add(key, false);
- }
- private void Lifecycle_GameUpdate(IClientPluginContext context, GameUpdateArgs GameUpdateArgs)
- {
- if (_keyStatesChanged.TryGetValue(Keys.LButton, out bool down))
- {
- if (down)
- Console.WriteLine("Mouse down");
- else
- Console.WriteLine("Mouse Up");
- }
- // Clear at the end of frame so events can handle next frame
- _keyStatesChanged.Clear();
- }
- public override void OnStop(IClientPluginContext context)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement