I don't have MacOS computer for testing the code. Anyone have who has MacOS computer please help, the code is here:
https://forum.lazarus.freepascal.org/index.php/topic,42439.msg297949.html#msg297949
I've just tried it with Lazarus 3.99 (4.99) + FPC 3.3.1 running on macOS 15.1.1 Sequoia. The project builds and runs, but the bat does not respond to any cursor movements.
It seems that GetKeyState is not implemented on macOS. Cmd clicking the GetKeyState function call, just reveals this (non)implementation...
function TWidgetSet.GetKeyState(nVirtKey: Integer): Smallint;
begin
Result := 0;
end;
However, your suggestion of using the OnKeyUp and OnKeyDown events works fine!
OK. I think I am starting to understand. I did not realize that you have to add a procedure using Object Editor.
The Object Editor is idiosyncratic on MacOS.
If you already have a function named the default name that it wants to create, it will fail and complain about unit or method not being find and highlight the last line of the unit section (with the semicolon).
If the default does not already exist, it will allow you to type in your own procedure name.
Now that I have added procedure I can see it is working. I made the body of the procedure Halt; so it will stop the program, because that is proof enough that KeyDown has been detected, and I can run with that. Thank you to everyone for getting me over this hump.
One last question. The right-click to "Find Declaration of GetKeyState" is not working.
How do I fix that?
And since GetKeyState is not implemented on MacOS, I know it might be unMacLike, but let's say I wanted to implement it, how would I start, since I cannot find source file?
Perhaps I need to install Lazarus sources somewhere and point to them?
Thanks!
Bradley