Recent

Author Topic: How do I send CM_/CN_ messages to controls in a cross-platform manner? [SOLVED]  (Read 583 times)

carl_caulkett

  • Hero Member
  • *****
  • Posts: 654
* Mac Mini M1
* macOS 14.6.1
* Lazarus 3.4
* FPC 3.2.2

Back in my Delphi days, if I wanted to send messages to a control, I would use the WM_ Windows messages and send them to a control's Handle.

Presumably on the Mac this is a non-starter! However, I've just found TRon's excellent post https://forum.lazarus.freepascal.org/index.php/topic,63350.msg479697.html#msg479697 which shows how to use the TApplicationProperties component to intercept messages such as CN_KEYDOWN and CN_KEYUP, received on any control in my app.

This, then, begs the question, is it possible to send similar messages to a control of my choosing, and will this work equally on Mac, Linux and Windows?
« Last Edit: September 29, 2024, 11:38:26 pm by carl_caulkett »
"It builds... ship it!"

carl_caulkett

  • Hero Member
  • *****
  • Posts: 654
The reason I wanted to send messages to a control was tied up with my problem with macOS insisting on beeping on unhandled keyboard inputs. I managed to mitigate the problem to some extent by holding my TLazVirtualStringTree in a dummy TPageControl which certainly suppressed the beeping on cursor up and down keystrokes. But the beeping returned when I tried to use the LazMouseAndKeyInput.lpk package...

Code: Pascal  [Select][+][-]
  1. procedure TMain.PresetTreeKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  2. var
  3.   I: Integer;
  4. begin
  5.   case Key of
  6.     VK_PRIOR:
  7.       for I := 1 to PresetTreeRowsPerPage do
  8.         KeyInput.Press(VK_UP);
  9.     VK_NEXT:
  10.       for I := 1 to PresetTreeRowsPerPage do
  11.         KeyInput.Press(VK_DOWN);
  12.   end;
  13.   case Key of
  14.     VK_PRIOR, VK_NEXT, VK_HOME, VK_END:
  15.       Key := 0;
  16.   end;
  17. end;
  18.  

I eventually solved this problem by changing the macOS settings for Sound. All I had to do was to select a destination for "Play sound effects through" that didn't go to a speaker or an audio interface and the beeping vanished, which meant that I could get rid of all of the above malarkey  ;)



"It builds... ship it!"

 

TinyPortal © 2005-2018