Ocaml how to get keyboard event - ocaml

how can I get event from keyboard in Ocaml ? For example I need to get the two directional arrow ( left and right), how can I get that ?

Related

Getting mouse movement input rather than the cursor position (C++)

I want to have my code read the movement of the mouse and act accordingly, for example, if you are moving your mouse up, you print the mouse is moving up in the console and sort of like that. (I am using Windows 10.)
The problem is, I could find a lot of articles that take the coordinates of the mouse cursor, but couldn't find one that deals with the real raw mouse input. The reason I want to do it this way is that when your cursor hits the border and cannot go further, the cursor position wouldn't change and the program won't recognize the mouse movement even though the mouse is "physically" moving. Another problem is that certain programs can "lock" your cursor to stay in a fixed position. For example, most FPS games do that.
Therefore, I wanted to get the raw input that the sensor of the mouse gives to the computer and utilize them instead of cursor position.
Therefore, I wanted to get the raw input that the sensor of the mouse gives to the computer and utilize them instead of cursor position.
Use the Raw Input API for that. Call RegisterRawInputDevices() to register the target mouse device(s) you want to monitor (there could be multiple connected to the PC), and then handle WM_INPUT messages containing the raw input data from the mouse(s).

Move mouse in certain direction while holding key in C++

I just started with C++ and I've been messing around with mouse movements in C++. I'm currently trying to get the mouse to forever move to the right while I'm holding down a key, and stop when I'm not.
The only way I can find to achieve anything similar to this is to use GetAsyncKeyState and SetCursorPos, but that would just instantly move my cursor to a certain position. I want the mouse to just keep moving to the right (or whatever direction) while a key is held down.
How could I achieve this?
Raw Input for globally monitoring keyboard input, and SendInput to generate mouse input.

Detect mouse scroll in console application

I want to write a C++ program which will act as a feeder of a virtual joystick http://vjoystick.sourceforge.net/site/.
I now successfully use the mouse cursor position to feed X and Y axis. Now I want to use the mouse wheel to feed the Z axis. But I tried of finding the way to detect the scroll. Can anyone suggest me on this? I use MinGW compiler.
By the way, this is my code : http://pastebin.com/WuFV8X3h

Capture mouse movement in win32/Opengl

At the moment I simply use the WM_MOUSEMOVE message, but it limits the mouse movement to the maximum resolution. So what's the best way of capturing the mouse with Win32 (on a OpenGl window)? I don't want to use freeglut or any extra library.
For games and realtime DirectInput is very suitable, it's moderately hard to use.
That is not core win32 api, the winapi way of getting the input is either GetCursorPos/SetCursorPos driven by your own update loop, so you query and reset with your own frequency.
Or SetCapture and then upon WM_MOUSEMOVE you call SetCursorPos.
The point of setting the cursor pos is to give room for movement so you can get the delta, the amount the cursor moved since the last update and then put it back the cursor into the center of your window.
If you want to be able to capture mouse events after the mouse has existed the window, then you might want to look into the SetCapture function
If your problem is that you want to make a FPS game and you want your character to be able to spin in a continuous motion, then you want to set the mouse position to the center of the window after each mouse move event and handle input based on the difference between the position of the cursor when the mouse move event is fired and the center of the screen. To set the position of the mouse you can use the SetCursorPos function.
Your best bets are to either use DirectInput (which can be a bit of a pain to set up) or RawInput.
There is a fairly comprehensive example available in the Using RawInput page (See example 2).

SDL_GetMouseState doesn't work to get initial mouse position

Is there a way to get initial position of mouse in SDL 2.0 ? I try to get mouse coordinates by SDL_GetMouseState(&mouse_x,&mouse_y), however I get the result I expected only after using the function SDL_PollEvent() and also I can't see a value other than (0,0) if the mouse has not been moved at least once since begining of the program.Although I don't check SDL_MOUSEMOTION and connect SDL_GetMouseState() to it, I get mouse coordinates only when mouse is moved.So what's wrong? Or is SDL_GetMouseState() suitable to do so?
Edit : Why, Why is there no any answer?
Try calling SDL_PumpEvents() before SDL_GetMouseState().
The SDL updates the position of the mouse internally in SDL_PrivateSendMouseMotion, which is called by various mouse related functions in the same file.
These functions are called in the event loop processing function WIN_WindowProc in response to the mouse events dispatched by Windows.
Thus, if you do not move the mouse, no event is dispatched and the SDL does not know where the mouse is. The solution is to wait for a mouse event before requesting the position and to find a workaround until this event.
I know it's late, but just chipping in with a resolution I found.
If you get zero coordinates, call SDL_GetGlobalMouseState(&x, &y) then offset x and y by the window.x and window.y coordinates.