0

I actually have an external keyboard with 15 keys. I developped a program "console app" to make several things following an XML. My program actually works like that :

  • Program has been launched,
  • Initialization,
  • Loop with Console.ReadKey(),
  • If the key is exit, we exit the loop. If it's not, we launch what have been set in the XML file.

The fact is that, even if my program works very fine, I can only use it while having the focus of my console app (thanks to Console.ReadKey()).

I now want my program to work like that :

  • Program has been launched,
  • Initialization is made,
  • Reduce console app,
  • Still able to get the key press.

I already did something like that, without using hooks but I can't find my source code. I'm just able to remember that I had to set my main as threadable, to make get the function working.

I would like to know if there is another way to get the key press without focus and hooks or hotkeys ? Then, if nothing else exists, I would like to have "a comparison" between hooks, hotkeys or whatever exists, or explanations on how those solutions works. This way, I will finally be able to understand, and I will be able to know what to use, as I don't wan't to use what I'm not able to explain myself.

Thanks

BadPoussin
  • 74
  • 10
  • 1
    There are global hotkeys or hooks on windows – Sir Rufo Sep 05 '17 at 09:37
  • Possible duplicate of [Global keyboard capture in C# application](https://stackoverflow.com/questions/604410/global-keyboard-capture-in-c-sharp-application) – DarkBee Sep 05 '17 at 09:39
  • As i said in my post, I know that it exists. The problem is that hooks are often badly explained, and I don't want to use them if i'm not able to understand how it works. – BadPoussin Sep 05 '17 at 09:41
  • @Badpoussin You could take it as a learning opportunity to figure out how to do it and as always, if you get stuck ask another question on SO. – phuzi Sep 05 '17 at 10:01
  • @phuzi This is actually how i take it, and this is why I post this question. The fact is that i'm trying to understand how all this works, and I want some people to tell me how it works. This way, I will be able to search where I have been wrong. Asking a question doesn't stop me from trying to find the solution, as i'm working on understanding HotKeys – BadPoussin Sep 05 '17 at 10:06
  • 1
    @Badpoussin If any app doesn't have focus it will have to hook in to the windows api's, did this myself a few years ago. However I don't think there's a way around it. Have a look at the link in the answer DarkBee linked to. – phuzi Sep 05 '17 at 10:22
  • @phuzi I already had a look at it, but i doesn't contain the informations I was searchin for when I posted this question. I'll continue to search. – BadPoussin Sep 05 '17 at 12:12

0 Answers0