Jump to content

Delphi global hook only for Ctrl button?

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Stasonix

Stasonix

    Learning Programmer

  • Members
  • PipPipPip
  • 82 posts
  • Programming Language:C++, PHP, JavaScript, Delphi/Object Pascal, Pascal
  • Learning:C++, PHP, JavaScript, Delphi/Object Pascal
how can I check if Ctrl is KeyDown, do some function, but not only in my form, but whole OS? I see a many of examples, but there is only for all keys, I need only for Ctrl.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
In that case, you're going to have to use some system hooks. There should be some Windows API functions for this. Torry's Delphi Pages
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 765 posts
If you okay with polling approach, then you can use windows api GetKeyboardState or GetKeyState in a timer to see if Ctrl is down. For interrupt approach, you need to install system-wide hook to intercept keyboard messages. This hook notifies your program when it detects WM_KEYDOWN with Ctrl key specified.

Visit my tutorial (http://forum.codecal...elphi-code.html) to start learning about keyboard hook. However in your case, function KBHookHandler should not drop all messages, but to look for WM_KEYDOWN with Ctrl key specified messages and notifies (either by postmessage or sendmessage or through named piped) your program.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users