Hello.
I'd like to write an input devices manager, but I have absolutely no idea, how it should look like. Can you give me any tips or maybe source codes? I would like not to use DirectInput.
Thank you in advance.
Hello.
I'd like to write an input devices manager, but I have absolutely no idea, how it should look like. Can you give me any tips or maybe source codes? I would like not to use DirectInput.
Thank you in advance.
You could use windows messages to handle any input. I recall that DirectInput is just a winapi wrapper so it should work quite well. You can use MMSystem to handle joystick input.
You can use this link to figure out how to use MMSystem. If i'm not mistakin. http://msdn.microsoft.com/en-us/libr...377.aspx<br />
Hope this helps.
Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.
The idea Cronodragon suggested me was:
[pascal]
unit UBEInput;
interface
uses
Contnrs, UBELogger;
type
{ .: TDeviceType :. }
TDeviceType = (dtKeyboard, dtMouse, dtJoystick);
{ .: TInputDevice :. }
TInputDevice = class(TObject)
private
{ Private declarations }
FDeviceType: TDeviceType;
public
{ Public declarations }
constructor Create(); virtual;
procedure Update(); virtual; abstract;
property DeviceType: TDeviceType read FDeviceType write FDeviceType;
end;
{ .: TKeyboardDevice :. }
TKeyboardDevice = class(TInputDevice)
private
{ Private declarations }
FKeys: array[0..255] of Boolean;
public
{ Public declarations }
constructor Create(); override;
procedure Update(); override;
property DeviceType;
end;
{ .: TDeviceManager :. }
TDeviceManager = class(TObject)
private
{ Private declarations }
FDevices: TObjectList;
public
{ Public declarations }
constructor Create();
destructor Destroy(); override;
procedure AddDevice(const ADevice: TInputDevice);
procedure UpdateDevices();
function IsPressed(ADeviceType: TDeviceType; AButton: Byte): Boolean;
end;
implementation
{ TInputDevice }
constructor TInputDevice.Create;
begin
inherited Create();
end;
{ TKeyboardDevice }
constructor TKeyboardDevice.Create;
begin
inherited Create();
DeviceType := dtKeyboard;
end;
procedure TKeyboardDevice.Update;
begin
end;
{ TDeviceManager }
procedure TDeviceManager.AddDevice(const ADevice: TInputDevice);
begin
FDevices.Add(ADevice);
end;
constructor TDeviceManager.Create;
begin
inherited Create();
FDevices := TObjectList.Create(True);
end;
destructor TDeviceManager.Destroy;
begin
FDevices.Free();
inherited Destroy();
end;
function TDeviceManager.IsPressed(ADeviceType: TDeviceType;
AButton: Byte): Boolean;
var
I: Integer;
begin
for I := 0 to FDevices.Count -1 do
case ADeviceType of
dtKeyboard:
if (FDevices.Items[I] is TKeyboardDevice) then
Result := TKeyboardDevice(FDevices.Items[I]).FKeys[AButton];
end;
end;
procedure TDeviceManager.UpdateDevices;
var
I: Integer;
begin
for I := 0 to FDevices.Count -1 do
TInputDevice(FDevices.Items[I]).Update();
end;
end.
[/pascal]
What do you think of it? And how do I read the pressed keys? :?
Take a look at the Omega input unit. It looks very much like the code you posted. One downside (for you) is that it uses Directinput. Do you have reasons to not use that API?? I integrated it into my engine and it works OK.
When i'm back from switzerland, i send you that unit over MSN if you like.
Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.
I don't want to use DirectInput, because I don't want to integrate any DX stuff into my engine. But yes, send me the unit when you back - it surely is worth looking at it.
Anyway, I'm waiting for other opinions.
Ah i found something you might like.
http://www.delphipraxis.net/topic857...light=joystick
These sources read joystick input using the MMSystem unit. You might want to integrate this into you input-manager. Use windows messages to capture mouse and keyboard input.
The site is german. If you don't understand something (that's unlikely), you can contact me.
Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.
Thanks a lot, man.
Well, I think it might be useful, but right now I'd like to finish keyboard/mouse input classes. My idea was to iterate through the array and check if the key's pressed using GetAsyncKeyState. Do you think it's optimal?
I think using messages is little faster. Calling getASyncKeyState hunderds of times a sec, is likely to be slower than handling only a few messages (or none, when no key is pressed). Moreover, when you use messages, less code is executed when you press a key, because you only have to change one array entry. You only have to respond to some messages which will be send to you anyway.
Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.
Is there a way to know what values can be expected when reading axis?
E.g. i have logitech dual action gamepad.
When reading out the axis the lowest value get is about 480 and the highest is 1000 and 0 for when not touched. Is my gamepad at fault or mmsystem?
In total it has 4 axis (two thumbsticks, or whatever they are called). So i need to read out x and y for the first stick. The second has to be read out as z and r. Is there any logic for that? Or can the axis be numbered as well?
Are there documents on this?
Also how do i now what button is where on the gamepad? Or dont i need to know that? As for my gamepad the numbering seem to be correct, but does that also aply to other gamepads?
http://3das.noeska.com - create adventure games without programming
noeska, to my knowledge, joystick input in mmsystem uses the 0..65535 where 0 is completely to one side and 65535 is completely to the other side.
Buttons are bitpacked into a byte structure afaik.
Have you calibrated your joystick?
Peregrinus, expectavi pedes meos in cymbalis
Nullus norvegicorum sole urinat
Bookmarks