How do you extract the VK_XXX code when you receive an LM_KEYDOWN event? lazarus / 31-LCL ---------------------------------------------------------------------- vfclists · 2024-10-08 09:49 I'm developing an app which needs to monitor some keys via AddOnUserInputHandler. For instance in the event below if the message is LM_KEYDOWN how would I know which actual key was pressed? procedure InputHandler(Sender:TObject; Msg:Cardinal); If the VK_XXX code embedded in the LM_KEYDOWN value or does it have to be retrieved from somewhere else? Would that have to come from the Application itself? ---------------------------------------------------------------------- cdbc · 2024-10-08 09:54 Hi The 'Key' value would be in either WParam or LParam of the message... After all, it's just a numeric value. Just my 2 cents worth Regards Benny ---------------------------------------------------------------------- Thaddy · 2024-10-08 10:00 It is stored in wparam. lparam stores additional information such as repeat counts and scan code. See msdn: https://learn.microsoft.com/en-us/windows/win32/inputdev/wm-keydown That info is in the TMsg record, but it depends on the message on how to interpret it. ---------------------------------------------------------------------- vfclists · 2024-10-08 10:01 Quote from: cdbc on October 08, 2024, 11:54:22 amHi The 'Key' value would be in either WParam or LParam of the message... After all, it's just a numeric value. Just my 2 cents worth Regards Benny Msg is a plain Cardinal. Are WParam and LParam functions, or do I have to cast Msg to some other type to obtain the Key? ---------------------------------------------------------------------- Thaddy · 2024-10-08 10:04 msg is not a plain cardinal it is a record. In the case of a Cardinal, that is only true if it is 32 bit pointer to msg, in the case the message is a pointer, which it isn't, it is not cardinal but prtuint. You did not read my link....which is slightly annoying late in the morning. I' ll have some lunch. Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i typedef struct tagMSG {  HWND   hwnd;      // Handle to the window that receives the message  UINT   message;   // Message identifier  WPARAM wParam;    // Additional message information (depends on the message)  LPARAM lParam;    // Additional message information (depends on the message)  DWORD  time;      // Time at which the message was posted  POINT  pt;        // Cursor position in screen coordinates when the message was posted  DWORD  lPrivate;  // Reserved for use by the system} MSG, *PMSG;Or look in the windows unit to see the pascal representation, which is the same. ---------------------------------------------------------------------- Sieben · 2024-10-08 10:08 @vcflists: Since you still seem to be working on the same issue I wonder if you read this reply...? ---------------------------------------------------------------------- Thaddy · 2024-10-08 10:16 At second glance, it may be that not the whole record is passed. I will have a look at third glance, because that would maybe be a bug since it suggests you have not all message information. and that is bad... Anyway for the answer to LM_KEYDOWN the answer should be correct. better solution is along these lines:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TForm1 = class(TForm)    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);  private    { private declarations }  public    { public declarations }  end; var  Form1: TForm1; procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin  if Key = VK_K then    ShowMessage('K key pressed!');end;that may be sufficient. You can also apply this to controls instead of the form, of course. ---------------------------------------------------------------------- vfclists · 2024-10-08 10:58 Quote from: Thaddy on October 08, 2024, 12:04:50 pmmsg is not a plain cardinal it is a record. In the case of a Cardinal, that is only true if it is 32 bit pointer to msg, in the case the message is a pointer, which it isn't, it is not cardinal but prtuint. You did not read my link....which is slightly annoying late in the morning. I' ll have some lunch. Code: C  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i typedef struct tagMSG {  HWND   hwnd;      // Handle to the window that receives the message  UINT   message;   // Message identifier  WPARAM wParam;    // Additional message information (depends on the message)  LPARAM lParam;    // Additional message information (depends on the message)  DWORD  time;      // Time at which the message was posted  POINT  pt;        // Cursor position in screen coordinates when the message was posted  DWORD  lPrivate;  // Reserved for use by the system} MSG, *PMSG;Or look in the windows unit to see the pascal representation, which is the same. Apologies for upsetting your mood just when you want to have some reinforcement. This is the type used in the user input event. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type TOnUserInputEvent = procedure(  Sender: TObject;  Msg: Cardinal) of object;  I'm also using Linux though I suspect the Linux events may have been remapped to make them fit with the Windows model. There is an example here - https://forum.lazarus.freepascal.org/index. php/topic,27980.msg173912.html#msg173912 and another from - http://lazarusroad.blogspot.com/2011/07/make- generic-control-behaves-like.html Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TMyPanel.UserInputHandler(Sender: TObject; Msg: Cardinal);var AControl: TControl;begin case Msg of   LM_LBUTTONDOWN, LM_LBUTTONDBLCLK, LM_RBUTTONDOWN, LM_RBUTTONDBLCLK,   LM_MBUTTONDOWN, LM_MBUTTONDBLCLK, LM_XBUTTONDOWN, LM_XBUTTONDBLCLK:   begin     AControl := Application.MouseControl;     if (AControl <> Self) and not IsParentOf(AControl) then       Visible := False;   end; end;end;  I have a feeling in that the event may be too  high level or I may have to cast it or treat as a pointer to something else, or get some additional info from the Application object. In any case I've noticed an AddOnKeyDownHandler event which may be more suitable for this problem. ---------------------------------------------------------------------- vfclists · 2024-10-08 11:06 Quote from: Sieben on October 08, 2024, 12:08:14 pm@vcflists: Since you still seem to be working on the same issue I wonder if you read this reply...? That part of the problem is functionally complete. I put back the OnKeyXXX events into a subclass of TPanel, but they are not actually needed for the event I want to trap as key events on panels are usually caught by the controls placed on them. I originally handled the response in the form's KeyPreview event but I'm now moving it in a separate component. ---------------------------------------------------------------------- Sieben · 2024-10-08 13:37 Another one you might want to have a look at if you didn't already: LCL Key Handling.