Input System Using Windows Messages?

Started by
4 comments, last by yadango 17 years, 4 months ago
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!
Advertisement
Why not use SDL as a cross-platform layer for this stuff?
You can build your Input System over it.
Try MSDN, search for example : Mouse Input, Keyboard Input. :)

Although, you might want to have some better input library.
Sincerely,Arto RuotsalainenDawn Bringer 3D - Tips & Tricks
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=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
msdn: Keyboard Input
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.

This topic is closed to new replies.

Advertisement