Monday, November 9, 2009

Global Windows keyboard & mouse activity detection



Here's a problem faces a lot of people & its solutions on the web aren't simple as it could be, here's a C/C++ code that detects a hit on CTRL key, for more keys check the virtual keys codes page http://msdn.microsoft.com/en-us/library/ms927178.aspx , It should be better if this code has its own thread that detects keys as long as it's alive.



bool ClickDetector()
{
if(GetAsyncKeyState(0x11) ==-32768)
{
printf("CTRL pressed!");
return true;
}
return false;
}

This code can work with C#, C++/CLI & any .NET Language by Importing the DLL "user32.dll"



No comments:

Post a Comment