PDA

View Full Version : Fully reading keyboard and mouse in GLUT and FPC



cronodragon
29-10-2007, 08:11 PM
I see GLUT events for keyboard and mouse aren't very powerful, it doesn't tell when keys are pressed and released. Also I'd prefer and event-less system. Are there any units to use with FPC that can read everything from the mouse and keyboard?

Regards!
-Marco

jdarling
30-10-2007, 12:27 PM
The keyboard is fairly simple to get back, everything to do with the mouse is another story. Below is a simple IsKeyDown function that you can include to find out if any key (using VK's) is down or not. You should also be able to pass in a byte (eg: ord('a')) to find out if normal keys are pressed as well.function IsKeyDown(vk: TVirtualKeyCode): Boolean;
begin
if active then
result := GetAsyncKeyState(vk)<>0
else
result := false;
end;

If you find a way to get the mouse without using GLUT I'd love to hear it. I asked the same question almost a month ago and found no answers yet.

If I remember properly, GetAsyncKeyState is defined in LCLIntf but it may have been in Windows. If its in Windows there is an identical version in Linux and Mac as I've compiled the above in all 3 environments.

cronodragon
30-10-2007, 02:26 PM
Thanks for that example, it will be very useful. Well, maybe I can stick to GLUT's mouse events, the keyboard was my main concern.

And what about the joystick/paddle? Is there a way to read those devices? :?

jdarling
31-10-2007, 12:39 PM
At the point that you start to want Joystick, Paddle, Game pad, Mouse, etc... Its actually easier and better (read A LOT LESS CODE and TIME) to switch to SDL. Use SDL to initialize your OpenGL window, then use standard OpenGL code to render. Now you can use all of the events and handlers surfaced in SDL. S2DL, Phoenix, and even the root JEDI-SDL surface great handlers for such things.

The down side is that you have another set of DLL's to ship with your application (or a side set of instructions on how to install SDL for the target platforms). The up side is that you don't have to write all of the VERY custom code on each platform you plan on supporting.