Key Control on Windows, Linux and Mac

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Key Control on Windows, Linux and Mac

Postby Julio Jerez » Wed Feb 23, 2011 12:32 am

How people who write Games for Linux and Macs deal with keyboar control?
In windows system there is a funtion name GetAsyncKeyState which is very cool bacase it just read the key code, not just for one Key but for as many as you touch on the keyboard without any initial delays.
This is very nice because the keys in the keyboard act like bottom.

The Qt GUI does not have support for Asyncronous Key reading, so I need to use and Operating system call, but I do not know what is the equivalent of GetAsyncKeyState for Linux and Mac
does any one knows that?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Key Control on Windows, Linux and Mac

Postby thedmd » Wed Feb 23, 2011 4:26 am

The simplest solution is to have a map of keystate and modify it in OnKeyDown/OnKeyUp (Qt have equivalent for those events for sure). But this is not reliable.
In our games we use three events to drive keyboard input: OnKeyDown, OnKeyUp and OnChar (text input), so no async key state checks.
thedmd
 

Re: Key Control on Windows, Linux and Mac

Postby JernejL » Wed Feb 23, 2011 4:46 am

GetKeyboardState is far better - you get clear information on exact unique button pressed - like the issues with left & right shift.. linux should have a variant of this but probably something like reading.. "/dev/input/".
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Key Control on Windows, Linux and Mac

Postby thedmd » Wed Feb 23, 2011 5:56 am

The reason for not using GetKeyboardState() is that I prefer event driven solutions. Qt is event driven and I think it is good to follow this path.
In reality, this is up to the programmer to use async way or event way to handle input.
thedmd
 

Re: Key Control on Windows, Linux and Mac

Postby JernejL » Wed Feb 23, 2011 9:18 am

thedmd wrote:The reason for not using GetKeyboardState() is that I prefer event driven solutions. Qt is event driven and I think it is good to follow this path.
In reality, this is up to the programmer to use async way or event way to handle input.


Not everyone uses QT..
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1587
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Key Control on Windows, Linux and Mac

Postby thedmd » Wed Feb 23, 2011 10:16 am

Julio is, that should be good enough reason to use event driven approach in Newton examples. IMHO
thedmd
 

Re: Key Control on Windows, Linux and Mac

Postby Julio Jerez » Wed Feb 23, 2011 3:31 pm

The keyevent in QT are nice but they are too slow for realtime graphics update.

I just added the added forward backward, and sideways navigation.
But is is not good because Qt keyboard event are too slow.
I can no figure out how to do it with the Qt Framework.
basically I the scene moves at the same rate of typing a senctence on a text editor.
I am sure there has to be a way to get faster update by so fat I had not luck.
I will post the question on the Qt forum to see what they say.

If anyne synk to SVN you cna see what I mean abpu teh key controll.

basically what is needed is a function the read the keyCode asyncronouslly just like GetAsynKeyStae in windows does.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Key Control on Windows, Linux and Mac

Postby Stucuk » Thu Feb 24, 2011 3:35 am

Julio are you doing it like the following:

Code: Select all
procedure OnKeyDown(Key : Whatever);
begin
 if Key = Something then
 SomeMovement := SomeMovement +1;
end;


If so then you should instead store the values in an array and in the rendering code add the movement.

I.E

Code: Select all
procedure OnKeyDown(Key : Whatever);
begin
 Keys[Key] := True;
end;

procedure OnKeyUp(Key : Whatever);
begin
 Keys[Key] := False;
end;

procedure ILikeToRenderStuff;
begin
 if Key[Something] then
 SomeMovement := SomeMovement +1;
end;
User avatar
Stucuk
 
Posts: 801
Joined: Sat Mar 12, 2005 3:54 pm
Location: Scotland


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 0 guests