title: Win32 - How Do I Intercept and Process Keyboard Input?
body: <p>I am trying to create a simple program I can use to wrap console software. I have a basic window with an EDIT component. I know I can use <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms646281(v=vs.85).aspx" rel="nofollow"><code>WM_KEYUP</code></a> and others to intercept keyborad input. I can't seem to discover an effective way to convert any of the parameters of <code>CALLBACK WinProc</code>; whereupon I will be able to complete this portion of my program:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  
  #define IDC_MAIN_EDIT   101
  #define WIDTH 800
  #define HEIGHT 600
  
  LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
  
  int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nShowCmd) {
      WNDCLASSEX wClass;
      ZeroMemory(&amp;wClass,sizeof(WNDCLASSEX));
      wClass.cbSize=sizeof(WNDCLASSEX);
      wClass.hbrBackground=(HBRUSH)COLOR_WINDOW;
      wClass.hCursor=LoadCursor(NULL,IDC_ARROW);
      wClass.hIcon=NULL;
      wClass.hIconSm=NULL;
      wClass.hInstance=hInst;
      wClass.lpfnWndProc=(WNDPROC)WinProc;
      wClass.lpszClassName="Window Class";
      wClass.lpszMenuName=NULL;
      wClass.style=CS_HREDRAW|CS_VREDRAW;
  
      if(!RegisterClassEx(&amp;wClass)) {
          int nResult=GetLastError();
          MessageBox(NULL,
              "Window class creation failed",
              "Window Class Failed",
              MB_ICONERROR);
      }
      HWND hWnd=CreateWindowEx(0,
              "Window Class",
              "Windows application",
              WS_OVERLAPPEDWINDOW,
              200,
              200,
              640,
              480,
              NULL,
              NULL,
              hInst,
              NULL);
  
      if(!hWnd) {
          int nResult=GetLastError();
  
          MessageBox(NULL,
              "Window creation failed",
              "Window Creation Failed",
              MB_ICONERROR);
      }
  
      ShowWindow(hWnd,nShowCmd);
  
      MSG msg;
      ZeroMemory(&amp;msg,sizeof(MSG));
  
      while(GetMessage(&amp;msg,NULL,0,0)) {
          TranslateMessage(&amp;msg);
          DispatchMessage(&amp;msg);
      }
      return 0;
  }
  
  LRESULT CALLBACK WinProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) {
      static HWND hEdit;
      switch(msg) {
          case WM_DESTROY:
              PostQuitMessage(0);
              return 0;
              break;
          case WM_CREATE:
              hEdit = CreateWindowEx(WS_EX_CLIENTEDGE,
                  "EDIT",
                  "",
                  WS_CHILD|WS_VISIBLE|ES_MULTILINE|WS_VISIBLE|WS_VSCROLL|ES_MULTILINE,
                  0,
                  0,
                  WIDTH,
                  HEIGHT,
                  hWnd,
                  (HMENU)IDC_MAIN_EDIT,
                  GetModuleHandle(NULL),
                  NULL);
              HFONT hFont = CreateFont(0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT("Courier New"));
              SendMessage(hEdit, WM_SETFONT, (WPARAM)hFont, 0);
              SendMessage(hEdit,
                  WM_SETTEXT,
                  0,
                  (LPARAM)"Insert text here...");
                  break;
          case WM_SIZE:
              MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
              break;
      }
      return DefWindowProc(hWnd,msg,wParam,lParam);
  }
  </code></pre>
  
  <p>What I should have said is: I can't seem to discover a way to intercept keyboard input as chars. How can I intercept all normal keyboard input? </p>