0

Hi, i want to write a farming bot for a certain game.

What i want to achieve is while playing the game, when i press for example F1 then the service (console program or a .Net Core Worker Service) should press the button for example A,B,C for me. And pressing ESC then the service will stop writing ABC...

This should be happened on a event driven approach.

At the moment i just turn off the console Programm..

Pressing A,B,C is already realized with the "User32.Dll" wrapper. But how can i listen to the F1 or ESC event?

How can i do this with C# on Windows?

Benjamin Martin
  • 576
  • 1
  • 8
  • 27
  • refer this for console App- https://stackoverflow.com/questions/5891538/listen-for-key-press-in-net-console-app & https://www.syncfusion.com/faq/windowsforms/keyboard-handling/how-can-i-catch-keyboard-messages-on-a-application-wide-basis – Brijesh Dec 28 '22 at 15:12
  • @Brijesh Both of those approaches would require the console/application to be in FOCUS to catch the keypress event. If you want to capture keypresses when your app is NOT IN FOCUS, then you can either use a (1) Low Level Keyboard Hook via WK_KEYBOARD_LL, or (2) Register a Hotkey with the system. [Examples of both approaches can be found here](https://stackoverflow.com/questions/3654787/global-hotkey-in-console-application). – Idle_Mind Dec 28 '22 at 20:17

0 Answers0