That looks promising, but I don't know how to use it, and there's no examples on that page.
I'll better explain what's going on. In my program, the program uses keybd_event() quite a bit. I've got the event for both the downs and the ups in the code, but if someone happens to close the program before the keyup is launched, they'll have to restart the computer so the "button will be release." I have a function that has all the keyup functions in it, I just need it to be called when the program is closed, much like the JavaScript onunload function (
http://www.w3schools.com/jsref/jsref_onunload.asp).
After reading through the function you gave me, it looks like it could work, if I knew how to use it. Is there any examples that will show me how to accomplish what I want with that function?
Edit: I figured out how to use the functions. Here's what I have:
#include <iostream>
#include <windows.h>
using namespace std;
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
if(CEvent == CTRL_CLOSE_EVENT)
{
cout << "You are closing my program.";
}
return TRUE;
}
int main()
{
if(SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler,TRUE)==FALSE)
{
cout << "The handler is not going to work.";
}
int i;
while(1)
{
i = 1;
}
return 0;
}
It almost works, when it gets closed, it displays a message, but then the program crashes instead of just closing afterward, is there another command I need to use to have it close?