Ver Mensaje Individual
  #2  
Antiguo 04-02-2010
Avatar de roman
roman roman is offline
Moderador
 
Registrado: may 2003
Ubicación: Ciudad de México
Posts: 20.269
Reputación: 10
roman Es un diamante en brutoroman Es un diamante en brutoroman Es un diamante en bruto
Hola, bienvenido al Club Delphi, tu casa amiga

La API de Windows cuenta con la función SetCursorPos que te puede servir para colocar el puntero del ratón en cualquier lugar. Puedes entonces valerte del evento OnKeyDown para mover el cursor según la tecla de flecha que se oprima.

Te pongo un ejemplo en Delphi, pero no debe ser mayor problema traducirlo a C++.

Código Delphi [-]
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
        procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
        procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    private
        StartX, StartY: Integer;
        Moving: Boolean;
    end;

var
    Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
const
    Arrows: set of Byte = [VK_LEFT..VK_DOWN];
    Speed = 15;

begin
    if Key in Arrows then
    begin
        if not Moving then
        begin
            Moving := true;

            StartX := Mouse.CursorPos.X;
            StartY := Mouse.CursorPos.Y;
        end;

        case Key of
            VK_LEFT: Windows.SetCursorPos(StartX - Speed, StartY);
            VK_UP: Windows.SetCursorPos(StartX, StartY - Speed);
            VK_RIGHT: Windows.SetCursorPos(StartX + Speed, StartY);
            VK_DOWN: Windows.SetCursorPos(StartX, StartY + Speed);
        end;

        StartX := Mouse.CursorPos.X;
        StartY := Mouse.CursorPos.Y;
    end;
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
    Moving := false;
end;

end.

Claro que esto funcionaría sólo mientras el formulario tenga el foco.

// Saludos
Responder Con Cita