[Solved] DirectX/Win32 Input Madness

Started by
1 comment, last by Jemburula 17 years, 11 months ago
Hello everyone, I posted a couple of weeks ago and the replies I got I followed up and experimented but didn't get very far. My problem is in my DX app I have created a console: I want the console to support both upper/lower case letters, punctuation and numbers. At the moment I have been using the wParam passed like so:
LRESULT CALLBACK WinProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
  switch(Msg)
  {
  case WM_CREATE:
    break;
  case WM_DESTROY:
    PostQuitMessage(0);
    break;
  case WM_KEYDOWN:
    switch(wParam)
    {
    case VK_ESCAPE:
      PostQuitMessage(0);
      break;
    case VK_OEM_3:
      D3D->ConsoleToggle();
      break;
    case VK_RETURN:
      D3D->ConsoleReturn();
      break;
    default:
      break;
    };
    if(wParam == 32 || wParam >= 48 && wParam <= 122)
    {
      D3D->ConsoleInput((char)wParam);
    };
    if(wParam == 190)
      D3D->ConsoleInput('.'); // as you can see this is a fairly unintuitive way of doing things...
    break;
  default:
    break;
  };
  return(DefWindowProc(hWnd, Msg, wParam, lParam));
};


But I don't know how to check whether Shift is down or up and also most of the punctuation characters don't work correctly. I'm fairly lost so if you could, please help with code or links to useful pages. I thank you all once again. Jem [Edited by - Jemburula on May 20, 2006 9:17:21 PM]
What we do in life... Echoes in eternity
Advertisement
Quote:Original post by Jemburula
But I don't know how to check whether Shift is down or up and also most of the punctuation characters don't work correctly. I'm fairly lost so if you could, please help with code or links to useful pages. I thank you all once again.


All you need to do is handle the WM_CHAR Windows message, and check the current character using the isprint function.

Example:
LRESULT CALLBACK WinProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam){  switch(Msg)  {  case WM_CREATE:    break;  case WM_DESTROY:    PostQuitMessage(0);    break;  case WM_CHAR:  {     if(isprint(wParam))     {        D3D->ConsoleInput((char)wParam);     }  }break;  case WM_KEYDOWN:    switch(wParam)    {    case VK_ESCAPE:      PostQuitMessage(0);      break;    case VK_OEM_3:      D3D->ConsoleToggle();      break;    case VK_RETURN:      D3D->ConsoleReturn();      break;    default:      break;    };    default:    break;  };  return(DefWindowProc(hWnd, Msg, wParam, lParam));};

Now, everything is taken care of for you [smile] Goodluck!
Ah thanks Drew, I'd rate you up again if you weren't already rated to the top [smile] Take it easy everyone. *Scrambles off into the madness again*
What we do in life... Echoes in eternity

This topic is closed to new replies.

Advertisement