Archived

This topic is now archived and is closed to further replies.

mrman131

DXInput in DelphiX

Recommended Posts

mrman131    122
When readings tutorials on DXInput, they say of being able to edit the 32 buttons for the keyboard. How would one go about assigning these buttons to keys?

Share this post


Link to post
Share on other sites
Savvy    122
Hello,

First of all you need to make a procedure to assign keys to a TKeyAssignList.:-

//####################
procedure AssignKey(var KeyAssignList: TKeyAssignList; State: TDXInputState;
const Keys: array of Integer);
var
i, i2: Integer;
KeyAssign: PKeyAssign;
begin
KeyAssign := @KeyAssignList[State];
FillChar(KeyAssign^, SizeOf(TKeyAssign), 0);

i2 := 0;
for i:=LOW(Keys) to HIGH(Keys) do
begin
if i2<3 then
KeyAssign^[i2] := Keys[i*]//remove the *
else
Exit;
Inc(i2);
end;
end;
//###################


Then in your form create (or whereever) you make a new keylist and set DXInpout to use the new Keylist:

//#####################
procedure TMainForm.FormCreate(Sender: TObject);
var
KeyList :TKeyAssignList;
begin
FillChar(KeyList, SizeOf(KeyList), 0);

AssignKey(KeyList, isUp, [Ord('K'), VK_UP, VK_NUMPAD8]);
AssignKey(KeyList, isDown, [Ord('J'), VK_DOWN, VK_NUMPAD2]);
AssignKey(KeyList, isLeft, [Ord('H'), VK_LEFT, VK_NUMPAD4]);
AssignKey(KeyList, isRight, [Ord('L'), VK_RIGHT, VK_NUMPAD6]);
AssignKey(KeyList, isButton1, [Ord('Q'), VK_SPACE]);
AssignKey(KeyList, isButton2, [Ord('X'), VK_RETURN]);
AssignKey(KeyList, isButton9, [VK_F2]);

DXinput1.Keyboard.KeyAssigns:=KeyList;
end;
//###########################


Hope this helps.

EDIT: seems the forum code tried to replace a few bits

-Sav


Edited by - Savvy on August 5, 2001 1:51:30 AM

Share this post


Link to post
Share on other sites
mrman131    122
thanks, that works. you just had one typo.
KeyAssign^[i2] := Keys
should be
KeyAssign^[i2] := Keys

The rest is great, really appreciate it.

Share this post


Link to post
Share on other sites