求Delphi directinput 的用法和详细Demo

cuiba1105 2013-07-03 08:09:44
求Delphi directinput 的用法和详细Demo 哪位大侠给看看.详细的
...全文
261 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
cuiba1105 2013-07-05
  • 打赏
  • 举报
回复
贴错图了,
cuiba1105 2013-07-05
  • 打赏
  • 举报
回复
找不到,我还是直接说问题吧.
双击DXInput1,出现对话框

我想用代码来改变key1,key2的值,初始化读值
用一个文本,或者INI文件存放,如下:
left = 1 //1代表手柄按键的值
right = 2 //2代表手柄按键的值
怎么写,我看了DXInput1类,也不知道怎么写,太菜了
sololie 2013-07-05
  • 打赏
  • 举报
回复
http://pan.baidu.com/share/link?shareid=3153640892&uk=1124482001 这个带demo\Samples\.hlp文件,源码版
sololie 2013-07-05
  • 打赏
  • 举报
回复
sololie 2013-07-05
  • 打赏
  • 举报
回复
偶不知道你咋下载的,直接用上面官网的下载。
下载安装好,安装目录了的Samples目录下有9M多个demo,包括dxinput的
cuiba1105 2013-07-05
  • 打赏
  • 举报
回复
下载了N个,DelphiX版本的控件,没几个有DEMO 有DEMO的又没有DXInput的DEMO 谁发一个来啊.谢谢啊!!!!!!!!!
mdejtod 2013-07-03
  • 打赏
  • 举报
回复

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
sololie 2013-07-03
  • 打赏
  • 举报
回复
下载DelphiX组件,是DX9的,用里面的TDXInput控件,自带有详细的DEMO DelphiX 主页 http://www.micrel.cz/Dx/
cuiba1105 2013-07-03
  • 打赏
  • 举报
回复
能传一个DEMO给我吗,c993home@163.com

5,928

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧