Jump to content
  • Advertisement
Sign in to follow this  
og knuckles

WinAPI Keyboard Input

This topic is 1131 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Currently im working on a WINAPI keyboard input event-driven system. With not much success I am not fluent in win API so im sure I am either not using it correctly or I am missing something...possibly both tongue.png

#define _WIN32_WINNT 0x0500
#include "windows.h"



int main()
{
	MSG msg;
	//HWND consoleWindow = GetForegroundWindow();
	while (true)
	{
		if (PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}



	return 0;
}

obviously while true is just for debug purposes. So what I am trying to do is pull the applications messages from first key to last. However this code never moves pass the PeekMessage if statement. I have tried passing the consoleWindow handle as well and still nothing.

 

-this is a command Line window

-I am trying to get every key that is being pressed not just the last one so if I press 10 keys at once I need to be able to see 10 instances of KEYDOWN 

Edited by og knuckles

Share this post


Link to post
Share on other sites
Advertisement
You don't appear to be creating a window at all. You won't receive practically all messages without a fully created window (that also means you need a message loop which correctly processes at least the WM_CREATE/WM_NC_CREATE-family of messages). I'm not sure about the rules for the console window but I have my doubts if retrieving it via GetForegroundWindow() works. Do you even get a non-NULL handle?

Share this post


Link to post
Share on other sites

Can we just clarify, are you trying to create a command line application or a windowed application here?

 

If its a command line application, you don't need to use the message loop like that. Here is an example of a minimal console application using the console API of Win32.

Share this post


Link to post
Share on other sites

You don't appear to be creating a window at all. You won't receive practically all messages without a fully created window (that also means you need a message loop which correctly processes at least the WM_CREATE/WM_NC_CREATE-family of messages). I'm not sure about the rules for the console window but I have my doubts if retrieving it via GetForegroundWindow() works. Do you even get a non-NULL handle?

It does output a non-NULL handle. GetConsoleWindow() also works to return the handle to the window.

 

Can we just clarify, are you trying to create a command line application or a windowed application here?

 

If its a command line application, you don't need to use the message loop like that. Here is an example of a minimal console application using the console API of Win32.

Currently it is command line. I thought about going the inputBuffer route. I am just trying to avoid looping a lot... more like an event-driven listeners. So it only loops if there is input.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!