jkuhlmann / gainput

Cross-platform C++ input library supporting gamepads, keyboard, mouse, touch
http://gainput.johanneskuhlmann.de/
MIT License
858 stars 103 forks source link

unable to use with console applications on Windows #55

Open OverMalo opened 6 years ago

OverMalo commented 6 years ago

Hi,

I want to use your library to monitorize the keyboard on console application (without windows). is it possible or is it compulsory to have a HWND?

Regards,

xnhunter commented 6 years ago

GaInput requires using HWND through WinAPI to work with a keyboard/mouse etc. So, if you want to monitorize the keyboard in console you may take a look at this: Detect function keys in c++ console.

RicoP commented 6 years ago

One thing you could try is you can create a native windows application (something that starts with a WinMain and get's a handle passed in right away) but don't create a native win form window. Instead you can create a Console window with AllocConsole.

RicoP commented 6 years ago
#include <iostream>
#include <windows.h>
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, INT) {
  if (AllocConsole())
  {
    freopen("CONOUT$", "wt", stdout);
    freopen("CONIN$", "rt", stdin);
    SetConsoleTitle(L"Debug Console");
    std::ios::sync_with_stdio(1);
  }

  std::cout << "Hello\n" << std::endl;

  return 0;
}
RicoP commented 6 years ago

Ok forget it. I assumed you need a HINSTANCe to get access to the window, but you need a HWND handle. I couldnt find a way to get a handle. for the console...