求Delphi directinput 的用法和詳細Demo 哪位大俠給看看.詳細的
uj5u.com熱心網友回復:
uses
Windows, Messages, SysUtils, Variants, Classes, Forms, Graphics, Controls, Direct3D,
Dialogs, Direct3D9, StdCtrls, ActiveX, D3DX9, comobj, DirectInput,
ExtCtrls;
type
TDxInput = class
private
DInput : IDirectInput8;
keybord : IDIRECTINPUTDEVICE8;
mouse : IDIRECTINPUTDEVICE8;
joy : IDIRECTINPUTDEVICE8;
KeyT : array[0..255]of byte;
MouseT : TDIMouseState;
JoyT : TDIJoyState2;
DX,DY:integer;
public
constructor create(viewhand:HWND);
destructor Destroy; override;
function keydown(key:byte):bool;
function keydown2():integer;
function moudown(key:byte):bool;
function joydown(key:byte):bool;
function moux:integer;
function mouy:integer;
function mouz:integer;
function joyx:integer;
function joyy:integer;
function keyx:integer;
function keyy:integer;
procedure joyfree(ko:integer=0);
procedure getall();
procedure getkey();
procedure getmouse();
procedure getjoy();
end;
implementation
constructor TDxInput.create(viewhand: HWND);
var p:DWORD;
begin
p:=DISCL_FOREGROUND or DISCL_NONEXCLUSIVE;
DirectInput8Create(GetModuleHandle(nil),DIRECTINPUT_VERSION,IID_IDirectInput8,dinput,nil);
dinput.CreateDevice(GUID_SysKeyboard,keybord,nil);
keybord.SetDataFormat(c_dfDIKeyboard);
keybord.SetCooperativeLevel(viewhand,p);
dinput.CreateDevice(GUID_Sysmouse,mouse,nil);
mouse.SetDataFormat(c_dfdimouse);
mouse.SetCooperativeLevel(viewhand,p);
dinput.CreateDevice(GUID_Joystick,joy,nil);
if joy<>nil then
begin
joy.SetCooperativeLevel(viewhand,p);
joy.SetDataFormat(c_dfDIJoystick2);
end;
DX:=0;
DY:=0;
end;
destructor TDxInput.Destroy;
begin
if DInput<>nil then DInput := nil;
if keybord<>nil then keybord := nil;
if mouse<>nil then mouse:= nil;
if joy<>nil then joy:= nil;
inherited Destroy;
end;
procedure TDxInput.getall;
begin
getkey;
getmouse();
getjoy();
end;
procedure TDxInput.getjoy;
begin
getmouse;
if joy<>nil then
begin
joy.Acquire;
joy.GetDeviceState(sizeof(TDIJoyState2),@JoyT);
end;
end;
procedure TDxInput.getkey;
begin
keybord.Acquire;
keybord.GetDeviceState(sizeof(KeyT),@KeyT[0]);
end;
procedure TDxInput.getmouse;
begin
mouse.Acquire;
mouse.GetDeviceState(sizeof(TDIMouseState),@MouseT);
end;
function TDxInput.joydown(key: byte): bool;
begin
result := bool(JoyT.rgbButtons[key] and $80);
if joy=nil then result:=false;
end;
procedure TDxInput.joyfree(ko: integer);
var k,i:integer;
begin
k:=ko;
while k=ko do
begin
getjoy();
k:=1;
for i:=0 to 31 do
begin
if joydown(i)=true then k:=0;
end;
end;
if ko=1 then
begin
k:=0;
while k=0 do
begin
getjoy();
k:=1;
for i:=0 to 31 do
begin
if joydown(i) then k:=0;
end;
end;
end;
end;
function TDxInput.joyx: integer;
begin
result := trunc((JoyT.lX-32767)/32767);
if joy <> nil then
inc(DX,result*4)
else
result:=0;
inc(DX,moux);
end;
function TDxInput.joyy: integer;
begin
result := trunc((JoyT.lY-32767)/32767);
if joy <> nil then
inc(DY,-result*4)
else
result:=0;
inc(DY,-mouy);
end;
function TDxInput.keydown(key: byte): bool;
begin
result := bool(KeyT[key] and $80);
end;
function TDxInput.keydown2: integer;
var i:integer;
begin
for i:=0 to 255 do
begin
if bool(KeyT[i] and $80) then
begin
result := i;
exit
end;
end;
result := -1;
end;
function TDxInput.keyx: integer;
begin
result := 0;
if keydown(DIK_LEFT ) then
result:=-1;
if keydown(DIK_RIGHT) then
result:=1;
end;
function TDxInput.keyy: integer;
begin
result := 0;
if keydown(DIK_UP ) then
result := -1;
if keydown(DIK_DOWN) then
result:=1;
end;
function TDxInput.moudown(key: byte): bool;
begin
result := bool(MouseT.rgbButtons[key] and $80);
end;
function TDxInput.moux: integer;
begin
result := MouseT.lX;
end;
function TDxInput.mouy: integer;
begin
result := MouseT.ly;
end;
function TDxInput.mouz: integer;
begin
result := MouseT.lz;
end;
//使用方法:
FDxInput := TDxInput.create(Handle);
在定時器,或訊息回圈體中判斷
FDxInput.getkey;
if DxInput.keydown(DIK_L) then
uj5u.com熱心網友回復:
能傳一個DEMO給我嗎,[email protected]uj5u.com熱心網友回復:
下載DelphiX組件,是DX9的,用里面的TDXInput控制元件,自帶有詳細的DEMODelphiX 主頁
http://www.micrel.cz/Dx/
uj5u.com熱心網友回復:
下載了N個,DelphiX版本的控制元件,沒幾個有DEMO 有DEMO的又沒有DXInput的DEMO 誰發一個來啊.謝謝啊!!!!!!!!!uj5u.com熱心網友回復:
偶不知道你咋下載的,直接用上面官網的下載。下載安裝好,安裝目錄了的Samples目錄下有9M多個demo,包括dxinput的
uj5u.com熱心網友回復:
懶成那樣,給你3個地址,自己挑http://pan.baidu.com/share/link?shareid=2994796424&uk=1124482001
http://www.micrel.cz/Dx/download/delphix_all_in_one_10_0.rar
更多的原始碼或檔案看官網首頁的下面
http://www.micrel.cz/Dx/
uj5u.com熱心網友回復:
http://pan.baidu.com/share/link?shareid=3153640892&uk=1124482001這個帶demo\Samples\.hlp檔案,原始碼版
uj5u.com熱心網友回復:
找不到,我還是直接說問題吧.雙擊DXInput1,出現對話框

我想用代碼來改變key1,key2的值,初始化讀值
用一個文本,或者INI檔案存放,如下:
left = 1 //1代表手柄按鍵的值
right = 2 //2代表手柄按鍵的值
怎么寫,我看了DXInput1類,也不知道怎么寫,太菜了
uj5u.com熱心網友回復:
貼錯圖了,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/130126.html
標籤:VCL組件開發及應用
