View Full Version : Key Listen C#/C++

07-18-2012, 01:46 PM
I am trying to make a global 'hot key' for use in my SQL- I have to do a lot of scroll-to-bottom=>highlight text=>paste=>save=>close
So my thoughts were to make two of my function keys do this so
F4 => scroll to bottom
... use mouse to highlight ...
F5 => paste,save,close

instead of having to do ctrl + V, ctrl + S, click 'X'

I have found 'how' to listen in C++, and I am right now thinking of doing in C++; however, I have not done C++ in a while. I was looking for something in C# but the Key enum is part of forms class and while I can make re-make it or reference the namespace, it seems like all the keyboard interaction is for use in forms. I wanted to run a background console hidden. Even the API for RegisterHotKey (or whatever it's called) is form based.

Does anyone know if there is a C# that does not use forms?

Along with that,
Does anyone know the processor impact for running a form hidden VS a console hidden (if it won't cause a problem then I can just run the form hidden)

08-14-2012, 02:11 PM
I think, you will need to p/invoke (http://pinvoke.net/default.aspx/user32/RegisterHotKey.html) a WinAPI function.

08-14-2012, 03:14 PM
For C# you should have a look at global hooks and the getasynchkeystate() function