Sign in to follow this  
Unreal

Input System Using Windows Messages?

Recommended Posts

Hello There!!! I am planing to make an input System for my 3D engine. I was looking for DInput But i drop it cause Microsoft will also drop Dinput Development. And MS recommends to use Windows events for K/B and mouse!! I was looking on the internet to find some tutorials or example code of Input Systems that use only Windows Messages. I can't Find any! Exept this wonderfull nehe tutorial: http://nehe.gamedev.net/data/articles/article.asp?article=14 bu i want to check some more tutorials and I though to ask here if anybody know any good/advanced tutorial about input using windows messages to check out before i start making mine! Thanks for your time!

Share this post


Link to post
Share on other sites
Try MSDN, search for example : Mouse Input, Keyboard Input. :)

Although, you might want to have some better input library.

Share this post


Link to post
Share on other sites
I'm a big fan of using the <windowsx.h> message crackers to deal with processing Windows messages. Don't know if this is any use but:


#include <windows.h>
#include <windowsx.h>

bool Key[256];

// WinMain etc

void OnDestroy(HWND Hw)
{
PostQuitMessage(0);
}

void OnKey(HWND Hw,UINT Code,bool Down,int Repeat,UINT Flags)
{
Key[Code]=Down;
}

LRESULT CALLBACK WndProc(HWND Hw,UINT Msg,WPARAM wParam,LPARAM lParam)
{
switch(Msg)
{
HANDLE_MSG(Hw,WM_DESTROY,OnDestroy);

HANDLE_MSG(Hw,WM_KEYDOWN,OnKey);
HANDLE_MSG(Hw,WM_KEYUP,OnKey);

default: return DefWindowProc(Hw,Msg,wParam,lParam);
}
}




The message crackers take a lot of the pain out of decoding the WPARAM and LPARAM. The above example just updates an array of bools representing the state of keys which can be queried elsewhere in the game.

There are similar message crackers for WM_MOUSEMOVE, WM_LBUTTONDOWN and so on for interpreting mouse button and movement messages.

Alternatively, if you go to MSDN and do a search for any of the messages mentioned in the code snippet above or the mouse related messages I've mentioned, there will be a complete description of how to interpret the WPARAM and LPARAMs manually.

HTH

Share this post


Link to post
Share on other sites
using only windows messages you could use WM_KEYDOWN and WM_KEYUP messages in conjunction with GetAsyncKeyState, although u should probably prefer WM_INPUT if u have no issues with your app being XP or greater compatible.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this