How do I see what key user presses I suppose I have to do it with winapi? I want my program to write to text file what key user presses, like when he presses M it writes M to text file. I looked and I found one function but it only checks for one key. Thanks!

Recommended Answers

All 2 Replies

Use windows hooks, look at my code snippets for examples. [link]

Hey! It works if I put message box after my code, I changed the code abit to work with my command line app heres the start code(whole code is too long)

int main()
{HWND Handle = GetConsoleWindow();
HINSTANCE hInstance = (HINSTANCE)GetWindowLong( Handle, GWL_HINSTANCE );
	HHOOK KeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboardHookProc, hInstance, 0);

Problem is that now it won't log the keys :S, it works if I put messagebox after that code, but whats the problem?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.