Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 13-01-2020
MaxiDucoli MaxiDucoli is offline
Miembro
 
Registrado: feb 2006
Posts: 134
Poder: 19
MaxiDucoli Va por buen camino
SDL2 en Delphi

Buenas noches (acá en Argentina)
Estoy teniendo un problema con las librerías SDL2 para Delphi que no puedo resolver y en la web están todos los códigos fuentes como yo lo estoy haciendo.
Quizás alguien que entienda un poco me pueda guiar en qué estoy haciendo mal.

El asunto es el siguiente:

Estoy queriendo hacer que al presionar un botón del joystick, el programa se dé cuenta y me diga qué joystick es, el nombre el GUID, etc,etc.
Pero no me reconoce las presiones de los botones.

El código es el siguiente:

Código Delphi [-]
unit GetSDL2Joy;


interface

uses
  SDL2,Forms, System.Classes,sysutils,dialogs,Vcl.Controls, Vcl.StdCtrls, Vcl.ExtCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);

  private
  public
  end;

var
  Form1: TForm1;
  NJoysticks : integer;
  SDL_JOY : PSDL_JOYSTICK;

implementation

{$R *.dfm}

function SDL_JOYS() : string;
var
i :integer;
s : String;
sdlEvent: PSDL_Event;
exitloop: boolean;
begin
NJoysticks := SDL_NumJoysticks;
if SDL_Init(SDL_INIT_JOYSTICK) = -1 then  ShowMessage('No Joysticks Found');
if  NJoysticks >= 1 then
    begin
        SDL_JOY := SDL_JoystickOpen(0);
          if SDL_JOY = nil then ShowMessage('Joystick open error');
    end;

    for i := 0 to NJoysticks -1  do
      begin
      SDL_JOY := SDL_JoystickOpen(i);
      SDL_JoystickEventState(SDL_ENABLE);
      SDL_JOYSTICKUPDATE();
     // s := SDL_JoystickName(SDL_JOY);

          new( sdlEvent );
               while SDL_PollEvent( sdlEvent) = 1 do
                begin
                      case Evento^.type_ of

                      SDL_JOYBUTTONDOWN: begin
                      s :=  'FUNCIONA!!!!!!';
                      end;

                end;;

 SDL_JoystickClose(SDL_JOY);

 Result := s;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
//NJoysticks := SDL_NumJoysticks;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
Memo1.Text := SDL_JOYS();

end;

end.

Por lo que creo, en el while del evento SDL_JOYBUTTONDOWN cuando presione la variable "s" me tiene que cargar un dato y mostrarlo en el MEMO.

Por ahora cargaría cualquier dato, eso no me importa. Una vez que me cargue el dato sé que funciona y ahí intento poner el código para que haga lo que quiero.

Alguien tiene idea de esto?
Responder Con Cita
  #2  
Antiguo 13-01-2020
Avatar de escafandra
[escafandra] escafandra is offline
Miembro Premium
 
Registrado: nov 2007
Posts: 2.197
Poder: 20
escafandra Tiene un aura espectacularescafandra Tiene un aura espectacular
Puedes probar con este pogramita de consola usando SDL2 así:


Código Delphi [-]
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows, Dialogs, SDL2;

var
  i: integer;
  sdlEvent: TSDL_Event;
  SDL_JOY : PSDL_JOYSTICK;
  s: String;
  Salir: boolean = false;
begin
  if SDL_Init(SDL_INIT_JOYSTICK) = -1 then  Writeln('No se encontraron Joysticks');
  for i := 0 to SDL_NumJoysticks -1  do
  begin
    SDL_JOY := SDL_JoystickOpen(i);
     Writeln(SDL_JoystickName(SDL_JOY)+#13);
  end;
  repeat
    while SDL_PollEvent(@sdlEvent) = 1 do
    begin
      if sdlEvent.type_  = SDL_JOYBUTTONDOWN then
      begin
        SDL_JOY := SDL_JoystickOpen(sdlEvent.jbutton.which);
        Writeln('Pulsado Boton de ' + SDL_JoystickName(SDL_JOY)+#13);
        Windows.Beep(1000, 100);
      end;
    end;
  until Salir;

end.




O usando Win Joystick:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Mmsystem,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    procedure JOY1ButtonDown(var Message: TMessage); message MM_JOY1BUTTONDOWN;

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
   if joySetCapture(Handle, JOYSTICKID1, 0, true) <> 0 then
     ShowMessage('No se puede capturar el Joystick');
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  joyReleaseCapture(JOYSTICKID1);
end;

procedure TForm1.JOY1ButtonDown(var Message: TMessage);
begin
  ShowMessage('Se ha pulsado un botón del Joystick');
end;

end.




Saludos.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Hormigas Locas 2018 - Delphi + SDL2 piXelicidio Gráficos 19 14-01-2019 15:27:07
Cargar librerías (SDL2) desde iOS kotai FireMonkey 0 09-09-2013 20:58:05


La franja horaria es GMT +2. Ahora son las 05:06:57.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi