Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Problema con hotkeys combinados. (https://www.clubdelphi.com/foros/showthread.php?t=87165)

carlosprotos 23-11-2014 03:41:11

Problema con hotkeys combinados.
 
Hola, tengo un problema con los hotkeys en delphi , hay una herramiena llamada Hotkey el cual lo uso para insertar hotkeys en un cuadro parecido al textbox , me funciona con los hotkeys de numeros,letras y todo eso. Pero cuando le agrego ALT+1 o ALT +k , o tambien CTRL+T , no me funciona la combinación.

Un claro ejemplo:
Código Delphi [-]
If GetKeystate(hk1.hotkey)<> 0 then
   checkbox.checked=true;
en el hk1.hotkey no me trabaja alponer ALT+1 (ejemplo)

Quisiera saber si hay alguna función o fuente que me ayude con ese problema. :rolleyes:

nlsgarcia 24-11-2014 00:08:42

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...

:rolleyes:

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.


La franja horaria es GMT +2. Ahora son las 20:40:56.

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