Advertisement
Guest User

Client Plugin Input Capturing Example

a guest
Jul 15th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. using Intersect.Client.Core;
  2. using Intersect.Client.Framework.GenericClasses;
  3. using Intersect.Client.Plugins;
  4. using Intersect.Client.Plugins.Interfaces;
  5.  
  6. using System;
  7. using System.Collections.Generic;
  8.  
  9. namespace Client.Plugins.InputExample
  10. {
  11. class InputExample : ClientPluginEntry
  12. {
  13. /// <summary>
  14. /// Tracks key state changes during this frame.
  15. /// Value is true for key down, false for key up.
  16. /// </summary>
  17. private Dictionary<Keys, bool> _keyStatesChanged = new Dictionary<Keys, bool>();
  18.  
  19. public override void OnStart(IClientPluginContext context)
  20. {
  21. Input.KeyDown += HandleKeyDown;
  22. Input.MouseDown += HandleKeyDown;
  23. Input.KeyUp += HandleKeyUp;
  24. Input.MouseUp += HandleKeyUp;
  25.  
  26. context.Lifecycle.GameUpdate += Lifecycle_GameUpdate;
  27. }
  28.  
  29. void HandleKeyDown(Keys key)
  30. {
  31. if (!_keyStatesChanged.ContainsKey(key))
  32. _keyStatesChanged.Add(key, true);
  33. }
  34.  
  35. void HandleKeyUp(Keys key)
  36. {
  37. if (!_keyStatesChanged.ContainsKey(key))
  38. _keyStatesChanged.Add(key, false);
  39. }
  40.  
  41. private void Lifecycle_GameUpdate(IClientPluginContext context, GameUpdateArgs GameUpdateArgs)
  42. {
  43. if (_keyStatesChanged.TryGetValue(Keys.LButton, out bool down))
  44. {
  45. if (down)
  46. Console.WriteLine("Mouse down");
  47. else
  48. Console.WriteLine("Mouse Up");
  49. }
  50.  
  51. // Clear at the end of frame so events can handle next frame
  52. _keyStatesChanged.Clear();
  53. }
  54.  
  55. public override void OnStop(IClientPluginContext context)
  56. {
  57. }
  58. }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement