Recent

Author Topic: change the function of a key in keyboard  (Read 268 times)

erol

  • New Member
  • *
  • Posts: 15
change the function of a key in keyboard
« on: February 24, 2025, 12:23:41 pm »
Hello All,

I would like to change the function of a key. There is a key next to Alt-Gr key on the right side on keyboard. It is between Alt-Gr and Ctrl keys. It's virtual code is VK_APPS. This key has a the same function with the mouse right click. I want to prevent it's normal function, but can not succeed. Instead, it should send a space character to Memo1. Program, gets locked when popup menu appears or sometimes, Memo1 is cleared. I mean it is not working stable. And I also want to add Ctrl+C function to Button1 to copy the content of Memo1.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   MouseAndKeyInput, LCLType;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     Button1: TButton;
  17.     Memo1: TMemo;
  18.     procedure Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  19.   private
  20.  
  21.   public
  22.     procedure SendKeys(Data: PtrInt);
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. { TForm1 }
  33.  
  34. procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
  35.   );
  36. begin
  37.   if (Key = VK_APPS) then
  38.     begin
  39.       Application.QueueAsyncCall(@SendKeys, 0);
  40.     end;
  41. end;
  42.  
  43. procedure TForm1.SendKeys(Data: PtrInt);
  44. begin
  45.   Memo1.SetFocus;
  46.   Application.ProcessMessages ;
  47.   KeyInput.Press(VK_SPACE);
  48. end;
  49.  
  50. end.
  51.                          
  52.  

erol

  • New Member
  • *
  • Posts: 15
Re: change the function of a key in keyboard
« Reply #1 on: February 26, 2025, 08:48:10 am »
I think, it requires low level programming for Apps key. But the program above, works with F1 without any problem. And I learned that this kind of work can be done easily with autohotkey.com
Code: Pascal  [Select][+][-]
  1. AppsKey::Space
is enough to write in a .ahk file.

 

TinyPortal © 2005-2018