Hi made a hook library that catches global events from the keyboard and mouse.
`private bool Install() //this function install all the hooks (mouse/keyobard)
{
bool started=true;
started &= _globalMouse.Install();
started &= _globalKeyboard.Install();
if(!started)
{
Uninstall();
}
return started;
}
private void Uninstall() //this function unistall all the hooks
{
_globalMouse.Uninstall();
_globalKeyboard.Uninstall();
}
private void run() // this is the method that is called by the thread to register and
// there should be caught all the global events (mouse/keyboard)
{
Instance.Install();
while(_running)
{
Thread.Sleep(0);
}
Instance.Uninstall();
}`
this is the creation and starting thread function:
public bool Start()
{
if(_thread!=null && _thread.IsAlive)
{
return true;
}
_running = true;
_thread = new Thread(run);
_thread.Start();
return _running;
}
The problem is that if I use the method Install()
directly from my form it's working. If it was the method start()
that should start the thread it isn't working (yes the thread remains alive, and yes I caught the needed event in the form correctly (worked with Install()
function).
I read on different pages that I need a cycle to pump messages from/to the system, but I don't know how to make it.
My question is how I can make my thread able to catch global events that worked fine in my form thread.