Link to home
Create AccountLog in
Delphi

Delphi

--

Questions

--

Followers

Top Experts

Avatar of _sunny_
_sunny_

Strange problem with catching Alt-F6 key on WM_KEYDOWN/WM_SYSKEYDOWN
That is the problem.
New application (Project1.dpr).
In my own message loop (PeekMessage/DispatchMessage) I can intercept all keys except the F6 when Alt is holded. WHY????????????

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of TOndrejTOndrej

could you perhaps show the code

Avatar of _sunny__sunny_

ASKER

procedure TForm1.Button1Click(Sender: TObject);
var
  M : TMsg;
begin
  while True do
    begin
      if PeekMessage(M, 0, 0, 0, PM_REMOVE) then
      begin
        if (M.Message = WM_KEYDOWN) or (M.Message = WM_SYSKEYDOWN) then
          // OutputDebugString do not outs any string about F6, but shows
          // F1, F2, F3 etc...
          OutputDebugString(PChar(IntToStr(M.hwnd) + ' ' +
                                  IntToStr(M.message) + ' '+
                                  IntToStr(M.wParam)));
        DispatchMessage(M)
      end
      else
        WaitMessage;
    end;
end;

I bet there is a program which has registered Alt+F6 as hotkey. If this is the case you cannot do anything about it...

Ciao, Mike

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of _sunny__sunny_

ASKER

:)

Just smiling? No comment? :-)

Avatar of _sunny__sunny_

ASKER

What API function you mean when talking about "Hot Key"? What do you mean when saying "registered Alt+F6 as hotkey"???

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


The API is RegisterHotKey

Avatar of _sunny__sunny_

ASKER

 Randomize;
  if not RegisterHotKey(Handle,
           GlobalAddAtom(PChar('SunnyAtom' + IntToStr(Random(50000)))),
           MOD_ALT, VK_F6) then
    RaiseLastWin32Error;

// It shows no error

I wasn't even able to show any F-key with Alt down, since it showed me repeated Alt WM_KEYDOWNs. Why do you need such a strange key catcher? It'd be much easier and better to override TForm1.WndProc and get the same with much less hassle. Regards, Artyom.

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of _sunny__sunny_

ASKER

If you answering, try your idea  at least before. RTFM, at last!

Could you please just let me know what's wrong about overriding WndProc? For now it's not that clear what you try to achieve by using custom message loop, and therefore I suggested a TESTED documented technique (this is for RTFM). Regards, Artyom.

Avatar of _sunny__sunny_

ASKER

Did you try to intercept WM_KEYDOWN in TForm1.WndProc ? Succeded? Why? Because an active control's WndProc takes the message. Not form. KeyPreview := True? Try it... with same result.
What I try to achieve? Oh... it is a long story. I have a small application (about 2 milion lines), I make its transition to Windows from DOS. So I have something like KeyPressed/ReadKey emulator inside. Of course it is a windows message loop.


Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of _sunny__sunny_

ASKER

Adjusted points from 200 to 500

No solution for you, but I found it strange enough to try it myself and it gives indeed the result you mentionned.
If I assign that key to a menu option, no reaction.
I tried to register the alt-f6 as hotkey which my machine allows me to do, but the key doesn't work.
It would surprise me if we have the same program running that registers that key except for windows itself probably.

ASKER CERTIFIED SOLUTION
Avatar of LischkeLischke

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of _sunny__sunny_

ASKER

Comment accepted as answer

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of _sunny__sunny_

ASKER

Cool, but it looks we still have a problem :(

Oh, thank you _sunny_. Didn't expect to get the points :-)

I'm sure with some extremly high effort you could catch system keys too, but you would need to capture them before the system gets them. Hence it would something like a keyboard driver. Not a very elegant solution, however :-(

Ciao, Mike

Avatar of _sunny__sunny_

ASKER

Oh, no! :)
I think users of previous versions will take some efforts to get into habit Alt+F8 key instead :)

Thank you.

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.

Delphi

Delphi

--

Questions

--

Followers

Top Experts

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.