Usando la tecla de acceso rápido incluso si la ventana se esconde en la bandeja. ¿Es posible en Delphi?

StackOverflow https://stackoverflow.com/questions/7814422

  •  26-10-2019
  •  | 
  •  

Pregunta

Necesito ocultar un formulario a la bandeja del sistema, pero al mismo tiempo quiero usar la tecla de acceso rápido, tal "Ctrl+3" para obtener texto de Tedit en mi formulario Hiden que se inserta en Firefox sendText (edit1.text); // en dicho método '. Sé cómo insertar texto, pero no sé nada sobre teclas de acceso rápido/ ninguna sugerencia. Gracias. Código de inserción de texto a continuación

procedure SendText(const Value: WideString);
var
  I: Integer;
  S: WideString;
  TI: TInput;
  KI: TKeybdInput;
const
  KEYEVENTF_UNICODE = $0004;
begin
  S := WideUpperCase(Value); 
  TI.Itype := INPUT_KEYBOARD;
  for I := 1 to Length(S) do
  begin
    KI.wVk := 0;
    KI.dwFlags := KEYEVENTF_UNICODE;
    KI.wScan := Ord(S[I]);
    TI.ki := KI;
    SendInput(1, TI, SizeOf(TI));
  end;
end;
¿Fue útil?

Solución

Para registrar una tecla de acceso rápido del sistema, debe usar el RegisterHotKey y UnRegisterHotKey funciones.

Verifique esta muestra

type
  TForm125 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    HotKey1 : Integer;
    procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;
  public

  end;

var
  Form125: TForm125;

implementation

{$R *.dfm}


procedure TForm125.FormCreate(Sender: TObject);
begin
  HotKey1 := GlobalAddAtom('MyAppHotkey1');//create a unique value for identify the hotkey
  if not RegisterHotKey(Handle, HotKey1, MOD_CONTROL, VK_F1) then //register the hotkey CTRL + F1
   ShowMessage('Sorry can not register the hotkey');
end;

procedure TForm125.FormDestroy(Sender: TObject);
begin
  UnRegisterHotKey(Handle, HotKey1);//unregister the hotkey
  GlobalDeleteAtom(HotKey1);//remove the atom
end;

procedure TForm125.WMHotKey(var Msg: TWMHotKey);
begin
  if Msg.HotKey = HotKey1 then
    ShowMessage('Hello'); // do your stuff
end;

Solo tenga cuidado con la combinación de clave que elija, porque se puede usar internamente para otra aplicación. Por ejemplo la combinación Control Número Firefox utiliza para cambiar las pestañas.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top