Fórum Ajuda em delphix no component dxinput. #348706

08/11/2007

0

alguém sabe como faz para o aplicativo enchergar o toque de um botão para o joystick ? tipo pressionando o botão 1 do joystick aparece num label a inscrissão pressionado..o algo assim..vlw t+


Gigatel

Gigatel

Responder

Posts

08/11/2007

Gigatel

Pesquisando na rede achei este comando.
procedure TForm2.Timer2Timer(Sender: TObject);
begin
 JoyErro := joyGetPos(joystickid1, @Joy);
    if JoyErro = JOYERR_NOERROR then
    begin
      if (Joy.wbuttons and joy_button1)> 0 then
      begin
        ListBox1.Items.Add(Edit1.Text);
        Label5.Caption := Inttostr(ListBox1.Items.Count);
     end;

  end;

coloquei em timer e atribuí seu intervalo a 1. más quando presciono o botão ele dispara queria que pegasse somente somente o primeiro toque.


Responder

Gostei + 0

09/11/2007

Gigatel

desta forma eu conseguir que a função para de disparar, mas não serve ele tem que disparar novamente assim que a tecla for disparada novamente..
 JoyErro := joyGetPos(joystickid1, @Joy);
    if JoyErro = JOYERR_NOERROR then
    begin
      if (Joy.wbuttons and joy_button1)> 0 then
      begin
        ListBox1.Items.Add(Edit1.Text);
        Label5.Caption := Inttostr(ListBox1.Items.Count);
        Timer2.Enabled := false;

     end;

  end;


alguém tem alguma idéia ? e tem mais não estou usando o componente.vlw t+


Responder

Gostei + 0

09/11/2007

Gigatel

presciso de algo assim tocou no caso acima da função o botão 1 e o programa registra e agurada novo toque e assim sucessivamente..se alguem puder dar uma luz,, vlw aí t+


Responder

Gostei + 0

12/11/2007

Gigatel

aki num para usa um IF BEGIN ou algo similar para poder detectar um toque por vez ? a funcão acima detecta o botão pressionado ou seja enquanto o botão do joystick estiver pressionado e ele manda informação para o memo, queria que aparecesse somente um toque independente de qnts segundo o botão ficar pressionado..ou seja clicou uma vez, registra somente akele momento, clicou novamente registranovamente...e por aí vai..vlw t+


Responder

Gostei + 0

12/11/2007

Gigatel

olha a função completa:
  private
     TimeOld:TDateTime;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
    seg,seg2,acum,a:integer;
    Joy:TJoyInfo;
    JoyErro:MMRESULT;

implementation

uses Unit1;

{$R *.dfm}



procedure TForm2.FormCreate(Sender: TObject);
begin
Timer1.Enabled := false;

end;
procedure TForm2.Timer1Timer(Sender: TObject);
begin
Edit1.Text := FormatDateTime(´HH:MM:SS:ZZZ´, TimeOld - NOW);
if Edit1.Text = MaskEdit1.Text then
begin
Timer1.Enabled := false;

end;

end;

procedure TForm2.Button1Click(Sender: TObject);
begin
if MaskEdit1.Text =(´__:__:__:___´) then showmessage (´coloca o tempo aí porra´);
if Button1.Caption = ´Ativar´ then
begin
TimeOld := Now;
Timer1.Enabled := True;

Button1.Caption := ´Desativar´;
end
else
begin
Timer1.Enabled := False;

Button1.Caption := ´Ativar´;
end;

end;

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action := cafree;
end;

procedure TForm2.Button3Click(Sender: TObject);
begin
Form1.IBQuery2.Insert;
Form1.IBQuery2CODIGO_ACESS.Value := Form1.IBQuery1CODIGO_PE.Value;
Form1.IBQuery2DATA_EXEC.Value := date;
Form1.IBQuery2TEMPO_PROG.Value := MaskEdit1.Text;
Form1.IBQuery2N_CHUTES.Value := strtoint(Label5.Caption);
Form1.IBQuery2TEMPO_CHUTE.Value := ListBox1.Items.Text;
Form1.IBQuery2.Post;
Form1.IBQuery2.Refresh;
Close;
end;

procedure TForm2.Timer2Timer(Sender: TObject);
begin
  JoyErro := joyGetPos(joystickid1, @Joy);
    if JoyErro = JOYERR_NOERROR then
    begin
      if (Joy.wbuttons and joy_button1)> 0 then
      begin
        ListBox1.Items.Add(Edit1.Text);
        Label5.Caption := Inttostr(ListBox1.Items.Count);
        Timer2.Enabled := false;

     end;

  end;
end;

end.


é isto aí..t+


Responder

Gostei + 0

13/11/2007

Gigatel

ok vlw ..más estou desistindo deste projeto vou tentar outro recurso, tendo em vista que este não tem futuro..vlw t+


Responder

Gostei + 0

24/11/2007

Gigatel

procurando e estudando achei este doc. no proprio componente será que dá para eu usar para o que estou querendo? eu chamei a função em uses, más não dá nada..
{ joystick device capabilities data structure }
type
  PJoyCapsA = ^TJoyCapsA;
  PJoyCapsW = ^TJoyCapsW;
  PJoyCaps = PJoyCapsA;
  {$EXTERNALSYM tagJOYCAPSA}
  tagJOYCAPSA = record
    wMid: Word;                  { manufacturer ID }
    wPid: Word;                  { product ID }
    szPname: array[0..MAXPNAMELEN-1] of AnsiChar;  { product name (NULL terminated string) }
    wXmin: UINT;                 { minimum x position value }
    wXmax: UINT;                 { maximum x position value }
    wYmin: UINT;                 { minimum y position value }
    wYmax: UINT;                 { maximum y position value }
    wZmin: UINT;                 { minimum z position value }
    wZmax: UINT;                 { maximum z position value }
    wNumButtons: UINT;           { number of buttons }
    wPeriodMin: UINT;            { minimum message period when captured }
    wPeriodMax: UINT;            { maximum message period when captured }
    wRmin: UINT;                 { minimum r position value }
    wRmax: UINT;                 { maximum r position value }
    wUmin: UINT;                 { minimum u (5th axis) position value }
    wUmax: UINT;                 { maximum u (5th axis) position value }
    wVmin: UINT;                 { minimum v (6th axis) position value }
    wVmax: UINT;                 { maximum v (6th axis) position value }
    wCaps: UINT;                 { joystick capabilites }
    wMaxAxes: UINT; { maximum number of axes supported }
    wNumAxes: UINT; { number of axes in use }
    wMaxButtons: UINT; { maximum number of buttons supported }
    szRegKey: array[0..MAXPNAMELEN - 1] of AnsiChar; { registry key }
    szOEMVxD: array[0..MAX_JOYSTICKOEMVXDNAME - 1] of AnsiChar; { OEM VxD in use }
  end;
  {$EXTERNALSYM tagJOYCAPSW}
  tagJOYCAPSW = record
    wMid: Word;                  { manufacturer ID }
    wPid: Word;                  { product ID }
    szPname: array[0..MAXPNAMELEN-1] of WideChar;  { product name (NULL terminated string) }
    wXmin: UINT;                 { minimum x position value }
    wXmax: UINT;                 { maximum x position value }
    wYmin: UINT;                 { minimum y position value }
    wYmax: UINT;                 { maximum y position value }
    wZmin: UINT;                 { minimum z position value }
    wZmax: UINT;                 { maximum z position value }
    wNumButtons: UINT;           { number of buttons }
    wPeriodMin: UINT;            { minimum message period when captured }
    wPeriodMax: UINT;            { maximum message period when captured }
    wRmin: UINT;                 { minimum r position value }
    wRmax: UINT;                 { maximum r position value }
    wUmin: UINT;                 { minimum u (5th axis) position value }
    wUmax: UINT;                 { maximum u (5th axis) position value }
    wVmin: UINT;                 { minimum v (6th axis) position value }
    wVmax: UINT;                 { maximum v (6th axis) position value }
    wCaps: UINT;                 { joystick capabilites }
    wMaxAxes: UINT; { maximum number of axes supported }
    wNumAxes: UINT; { number of axes in use }
    wMaxButtons: UINT; { maximum number of buttons supported }
    szRegKey: array[0..MAXPNAMELEN - 1] of WideChar; { registry key }
    szOEMVxD: array[0..MAX_JOYSTICKOEMVXDNAME - 1] of WideChar; { OEM VxD in use }
  end;
  {$EXTERNALSYM tagJOYCAPS}
  tagJOYCAPS = tagJOYCAPSA;
  TJoyCapsA = tagJOYCAPSA;
  TJoyCapsW = tagJOYCAPSW;
  TJoyCaps = TJoyCapsA;
  {$EXTERNALSYM JOYCAPSA}
  JOYCAPSA = tagJOYCAPSA;
  {$EXTERNALSYM JOYCAPSW}
  JOYCAPSW = tagJOYCAPSW;
  {$EXTERNALSYM JOYCAPS}
  JOYCAPS = JOYCAPSA;

{ joystick information data structure }
type
  PJoyInfo = ^TJoyInfo;
  {$EXTERNALSYM joyinfo_tag}
  joyinfo_tag = record
    wXpos: UINT;                 { x position }
    wYpos: UINT;                 { y position }
    wZpos: UINT;                 { z position }
    wButtons: UINT;              { button states }
  end;
  TJoyInfo = joyinfo_tag;
  {$EXTERNALSYM JOYINFO}
  JOYINFO = joyinfo_tag;

  PJoyInfoEx = ^TJoyInfoEx;
  {$EXTERNALSYM joyinfoex_tag}
  joyinfoex_tag = record
    dwSize: DWORD; { size of structure }
    dwFlags: DWORD; { flags to indicate what to return }
    wXpos: UINT;         { x position }
    wYpos: UINT;         { y position }
    wZpos: UINT;         { z position }
    dwRpos: DWORD; { rudder/4th axis position }
    dwUpos: DWORD; { 5th axis position }
    dwVpos: DWORD; { 6th axis position }
    wButtons: UINT;      { button states }
    dwButtonNumber: DWORD;  { current button number pressed }
    dwPOV: DWORD;           { point of view state }
    dwReserved1: DWORD; { reserved for communication between winmm & driver }
    dwReserved2: DWORD; { reserved for future expansion }
  end;
  TJoyInfoEx = joyinfoex_tag;
  {$EXTERNALSYM JOYINFOEX}
  JOYINFOEX = joyinfoex_tag;


será que agora tem como ?

achei um site em francês com este código, más não sei o que a função fáz
procedure TForm1.Form1Create(Sender: TObject);
var
myJoyCaps: JoyCaps; // Syntaxe Delphi -> myJoyCaps: TJoyCaps;
begin
joyGetDevCaps(joystickid1,@myJoyCaps,sizeof(myJoyCaps));
joySetCapture(self.Handle, joystickid1, 100, true);
end;

et puis par exemple ensuite j´utilise :
procedure TForm1.MMJOY1MOVE (var LocMessage: TMMJoyStick);
begin
Edit1.Text := IntToStr(LocMessage.ypos); 
Edit2.Text := IntToStr(LocMessage.xpos); 
trackbar1.position := LocMessage.ypos;
trackbar2.position := LocMessage.xpos;

Edit3.Text := floattostr(Percentage(LocMessage.ypos));
Edit4.Text := floattostr(Percentage(LocMessage.xpos));
end;

más tbm não conseguí colocar funcionar..

tá osso..heheheeflw


Responder

Gostei + 0

25/11/2007

Gigatel

tentei este código copila más tbm não funciona
begin
 JoyErro := joyGetPos(joystickid1, @Joy);
    if JoyErro = JOYERR_NOERROR then
    begin
      if (Joy.wbuttons and joy_button1)> 0 then
      begin
      JoyGil.wPeriodMin := 1;
      JoyGil.wPeriodMax := 400;
      ListBox1.Items.Add(Edit1.Text);
      ListBox2.Items.Add(FormatDateTime(´HH:MM:SS:ZZZ´, TimeOld - NOW));
      Label5.Caption := Inttostr(ListBox1.Items.Count);
      end;
   end;


e vamos tentando..


Responder

Gostei + 0

25/11/2007

Gigatel

tive que declarar estas variaveis..
var
  Form2: TForm2;
    seg,seg2,acum,a:integer;
    JoyGil:tagJOYCAPSA;
    Joy:TJoyInfo;
    JoyErro:MMRESULT;



flw


Responder

Gostei + 0

25/11/2007

Gigatel

achei esta função na rede será que dá para fazer o que eu quero ?

 interface   
    
  uses   
      Windows,   Messages,   Classes,   SysUtils,   mmSystem;   
    
  type   
      TMultimediaTimer   =   class(TComponent)   
      private   
          fTimerID:   Integer;   
          fEnabled:   Boolean;   
          fInterval:   WORD;   
          fResolution:   WORD;   
          fOnTimer:   TNotifyEvent;   
          procedure   SetEnabled(Value:   Boolean);   
          procedure   SetInterval(Value:   WORD);   
          procedure   SetResolution(Value:   WORD);   
          procedure   StartTimer;   
          procedure   StopTimer;   
      protected   
          procedure   Loaded;   override;   
          procedure   DoTimer;   virtual;   
      public   
          constructor   Create(AOwner:   TComponent);   override;   
          destructor   Destroy;   override;   
          class   function   TimerCaps:   TTimeCaps;   
          property   TimerID:   Integer   read   fTimerID;   
      published   
          property   Enabled:   Boolean   read   fEnabled   write   SetEnabled   default   False;   
          property   Interval:   WORD   read   fInterval   write   SetInterval   default   1000;   //   Milliseconds   
          property   Resolution:   WORD   read   fResolution   write   SetResolution   default   100;   //   Milliseconds   
          property   OnTimer:   TNotifyEvent   read   fOnTimer   write   fOnTimer;   
      end;   
    
  implementation   
    
  {   Multimedia   Timer   Callback   Function   }   
    
  procedure   TimerProc(uTimerID,   uMessage,   dwUser,   dw1,   dw2:   DWORD);   stdcall;   
  begin   
      TMultimediaTimer(dwUser).DoTimer;   
  end;   
    
  {   TMultimediaTimer   }   
    
  constructor   TMultimediaTimer.Create(AOwner:   TComponent);   
  begin   
      inherited   Create(AOwner);   
      fEnabled   :=   False;   
      fInterval   :=   1000;   
      fResolution   :=   100;   
  end;   
    
  destructor   TMultimediaTimer.Destroy;   
  begin   
      Enabled   :=   False;   
      inherited   Destroy;   
  end;   
    
  procedure   TMultimediaTimer.Loaded;   
  begin   
      inherited   Loaded;   
      if   Enabled   then   StartTimer;   
  end;   
    
  procedure   TMultimediaTimer.DoTimer;   
  begin   
      if   Assigned(fOnTimer)   then   
          fOnTimer(Self);   
  end;   
    
  procedure   TMultimediaTimer.SetEnabled(Value:   Boolean);   
  begin   
      if   Enabled   <>   Value   then   
      begin   
          fEnabled   :=   Value;   
          if   Enabled   then   
              StartTimer   
          else   
              StopTimer;   
      end;   
  end;   
    
  procedure   TMultimediaTimer.SetInterval(Value:   WORD);   
  begin   
      if   Interval   <>   Value   then   
      begin   
          if   Enabled   then   
              StopTimer;   
          fInterval   :=   Value;   
          if   Enabled   then   
              StartTimer;   
      end;   
  end;   
    
  procedure   TMultimediaTimer.SetResolution(Value:   WORD);   
  begin   
      if   Resolution   <>   Value   then   
      begin   
          if   Enabled   then   
              StopTimer;   
          fResolution   :=   Value;   
          if   Enabled   then   
              StartTimer;   
      end;   
  end;   
    
  procedure   TMultimediaTimer.StartTimer;   
  begin   
      if   not   ((csLoading   in   ComponentState)   or   (csDesigning   in   ComponentState))   and   (TimerID   =   0)   then   
      begin   
          with   TimerCaps   do   
          begin   
              if   Resolution   <   wPeriodMin   then   
                  fResolution   :=   wPeriodMin;   
              if   Resolution   >   wPeriodMax   then   
                  fResolution   :=   wPeriodMax;   
          end;   
          if   Interval   <   Resolution   then   
              fInterval   :=   Resolution;   
          if   Interval   >   0   then   
          begin   
              timeBeginPeriod(Resolution);   
              fTimerID   :=   timeSetEvent(Interval,   Resolution,   @TimerProc,   DWORD(Self),   TIME_PERIODIC);   
              fEnabled   :=   (TimerID   <>   0);   
          end;   
      end;   
  end;   
    
  procedure   TMultimediaTimer.StopTimer;   
  begin   
      if   TimerID   <>   0   then   
      begin   
          timeKillEvent(TimerID);   
          fTimerID   :=   0;   
          timeEndPeriod(Resolution);   
      end;   
  end;   
    
  class   function   TMultimediaTimer.TimerCaps:   TTimeCaps;   
  begin   
      if   timeGetDevCaps(@Result,   SizeOf(TTimeCaps))   <>   TIMERR_NOERROR   then   
          FillChar(Result,   SizeOf(TTimeCaps),   0);   
  end;   
    
  end.


vlw t+


Responder

Gostei + 0

26/11/2007

Gigatel

Problema resolvido. Não tem como fazer isso pelo joystick, tinha a nescessidade de usar o dipostivo externo via USB aí pensado e remoendo lebrei do teclado USB que pelo teclado poderia ser até mais fácil fazer, num deu outro resolví o problema rápidinho atrávés do onkeypress e daí foi só capturar uma tecla...vlw pelo esforço (mesmo qie ninguém tenha ajudado fica aki a dica), vlw t+


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar