Ver Mensaje Individual
  #2  
Antiguo 24-11-2014
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
carlosprotos,

Cita:
Empezado por carlosprotos
...tengo un problema con los Hotkeys en Delphi...cuando le agrego ALT+1 o ALT+K , o tambien CTRL+T , no me funciona la combinación...Quisiera saber si hay alguna función o fuente que me ayude con ese problema...


Revisa este código:
Código Delphi [-]
// Método 1 de Gestión de Combinaciones de Teclas
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
   KeyPreview := True;
end;

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin

   If (GetKeyState(VK_CONTROL) < 0) and
      (GetKeyState(VK_F1) < 0) and
      (GetKeyState(Ord('7')) < 0)
   then
      MessageDlg('Ctrl + F1 + 7',mtInformation,[mbOK],0);

   if (Shift = [ssCtrl]) and (Key = VK_F7) then
      MessageDlg('Ctrl + F7',mtInformation,[mbOK],0);

   if (Shift = [ssAlt]) and (Key = Ord('N')) then
      MessageDlg('Alt + N',mtInformation,[mbOK],0);

   if (Shift = [ssCtrl]) and (Key = Ord('N')) then
      MessageDlg('Ctrl + N',mtInformation,[mbOK],0);

   if (Shift = [ssAlt]) and (Key = Ord('1')) then
      MessageDlg('Alt + 1',mtInformation,[mbOK],0);

end;

end.
Código Delphi [-]
// Método 2 de Gestión de Combinaciones de Teclas
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure WM_KEYDOWN(var Msg : TMessage); Message WM_KEYDOWN;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WM_KEYDOWN(var Msg : TMessage);
begin

   If (GetKeyState(VK_CONTROL) < 0) and
      (GetKeyState(VK_F1) < 0) and
      (GetKeyState(Ord('7')) < 0)
   then
      MessageDlg('Ctrl + F1 + 7',mtInformation,[mbOK],0);

   If (GetKeyState(VK_CONTROL) < 0) and (GetKeyState(VK_F7) < 0)
   then
      MessageDlg('Ctrl + F7',mtInformation,[mbOK],0);

   If (GetKeyState(VK_MENU) < 0) and (GetKeyState(Ord('N')) < 0) then
      MessageDlg('Alt + N',mtInformation,[mbOK],0);

   If (GetKeyState(VK_CONTROL) < 0) and (GetKeyState(Ord('N')) < 0) then
      MessageDlg('Ctrl + N',mtInformation,[mbOK],0);

   If (GetKeyState(VK_MENU) < 0) and (GetKeyState(Ord('1')) < 0) then
      MessageDlg('Alt + 1',mtInformation,[mbOK],0);

end;

end.
Código Delphi [-]
// Método 3 de Gestión de Combinaciones de Teclas
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure MessageHandler(var Msg: TMsg; var Handled: Boolean);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
   Application.OnMessage := MessageHandler
end;

procedure TForm1.MessageHandler(var Msg: TMsg; var Handled: Boolean);
begin

   if (Msg.message = WM_KEYDOWN) then
   begin

      If (GetKeyState(VK_CONTROL) < 0) and
         (GetKeyState(VK_F1) < 0) and
         (GetKeyState(Ord('7')) < 0)
      then
         MessageDlg('Ctrl + F1 + 7',mtInformation,[mbOK],0);

      If (GetKeyState(VK_CONTROL) < 0) and (GetKeyState(VK_F7) < 0)
      then
         MessageDlg('Ctrl + F7',mtInformation,[mbOK],0);

      If (GetKeyState(VK_MENU) < 0) and (GetKeyState(Ord('N')) < 0) then
         MessageDlg('Alt + N',mtInformation,[mbOK],0);

      If (GetKeyState(VK_CONTROL) < 0) and (GetKeyState(Ord('N')) < 0) then
         MessageDlg('Ctrl + N',mtInformation,[mbOK],0);

      If (GetKeyState(VK_MENU) < 0) and (GetKeyState(Ord('1')) < 0) then
         MessageDlg('Alt + 1',mtInformation,[mbOK],0);

   end;

end;

end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32, Muestra 3 métodos de Gestión de Combinaciones de Teclas.

Revisa esta información:
Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 24-11-2014 a las 00:17:25.
Responder Con Cita