TestInputForm.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using Y.Utils.WindowsUtils.HookUtils;
  12. namespace Y.Test.Views
  13. {
  14. public partial class TestInputForm : Form
  15. {
  16. private static UserActivityHook Hook;
  17. public TestInputForm()
  18. {
  19. InitializeComponent();
  20. }
  21. private void TestInputForm_Load(object sender, EventArgs e)
  22. {
  23. Hook = new UserActivityHook(Assembly.GetExecutingAssembly().GetModules()[0]);
  24. Hook.OnMouseActivity += new MouseEventHandler(mouseHandler);
  25. Hook.KeyDown += new KeyEventHandler(keyHandler);
  26. Hook.Start();
  27. }
  28. private void mouseHandler(object sender, MouseEventArgs e)
  29. {
  30. Invoke(new Action(() =>
  31. {
  32. //textBox1.AppendText("[click1]");
  33. }));
  34. }
  35. private void keyHandler(object sender, KeyEventArgs e)
  36. {
  37. Invoke(new Action(() =>
  38. {
  39. textBox1.AppendText("[press" + e.KeyCode + "]");
  40. }));
  41. }
  42. }
  43. }