Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 626
  • Last Modified:

How can to discover if has a recorded RegisterHotKey in Windows?

How can to my application Delphi discover if has RegisterHotKey recorded for another program?
0
mccoymad
Asked:
mccoymad
  • 5
  • 4
  • 3
3 Solutions
 
jimyXCommented:
You can check the returned value of the function RegisterHotKey:

id2 := GlobalAddAtom('Hotkey2');
  if RegisterHotKey(Handle, id2, MOD_CONTROL + MOD_Alt ,VK_Delete) then
    showmessage('Registered')
  else
    showmessage('Error, Alt+Ctrl+ Del is already in use. Not registered');

Open in new window

0
 
mccoymadAuthor Commented:
No, no
You did not understand my problem!
I want to know I eat to detect if some hotkey was registered, any one! Not one hotkey specific!
0
 
jimyXCommented:
After deep search, it seems that you can not do that with just delphi code and you need to have a way to access the OS where the hotkeys are stored.

But you have an option of designing a testing application that attempts to loop through the different combination of the possible keys such as (Ctrl+Alt+A) and try to set it if not succeeded (used by another application) then release that and try the second combination (Ctrl+Alt+B) and so on until you scan all the common combinations:

Here is an example for testing Alt+Ctrl combination with A to Z:

 
procedure TForm1.Button1Click(Sender: TObject);
var
  i, j : integer;
begin
  for i := $41 to $41+25 do
    begin
      j := GlobalAddAtom('H');
      if not RegisterHotKey(Handle, j, MOD_ALT + MOD_CONTROL, i) then
        begin
          showmessage('Alt + Ctrl + '+ char(i) +' Not available');
        end
      else
        begin
          showmessage('Alt + Ctrl + '+ char(i) +' Available');
          UnRegisterHotKey(Handle, j);
          GlobalDeleteAtom(j);
        end;
    end;
end;

Open in new window


You can get all the Virtual keys from delphi.about.com:
http://delphi.about.com/od/objectpascalide/l/blvkc.htm

Here is an interesting topic discussing the same issue:
http://stackoverflow.com/questions/829007/find-out-what-process-registered-a-global-hotkey-windows-api

In this link there is a similar question as yours:
http://superuser.com/questions/26824/how-to-get-list-of-defined-shortcut-keys-in-the-start-menu


// Modifiers
Alt = MOD_ALT
Control = MOD_CONTROL
Shift = MOD_SHIFT
Win button = MOD_WIN

//virtual key codes of the alphabet because it is not clear in the above link from About.com:
A = $41;
B = $42;
C = $43;
D = $44;
E = $45;
F = $46;
G = $47;
H = $48;
I = $49;
J = $4A;
K = $4B;
L = $4C;
M = $4D;
N = $4E;
O = $4F;
P = $50;
Q = $51;
R = $52;
S = $53;
T = $54;
U = $55;
V = $56;
W = $57;
X = $58;
Y = $59;
Z = $5A;

Delete button = $2E; // or use VK_Delete directly

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
lomo74Commented:
I'm afraid jimyX is right --
the only chance you have is to check every combination of hotkey for availability --
there are 4 modifiers plus 26 letters (if you limit your search to alphabet...), total loops are 2^4*26=416 :-(
here is a more complete piece of code --

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows;

var
  a, c, s, w, m, h, id: Integer;
  desc: string;

const
  ALT: array[0..1] of string = (
    '',
    'Alt + '
  );
  CTRL: array[0..1] of string = (
    '',
    'Ctrl + '
  );
  SHIFT: array[0..1] of string = (
    '',
    'Shift + '
  );
  WIN: array[0..1] of string = (
    '',
    'Win + '
  );

begin
  try
    id := GlobalAddAtom('HotKey');
    for a := 0 to 1 do
      for c := 0 to 1 do
        for s := 0 to 1 do
          for w := 0 to 1 do begin
            m := a * MOD_ALT +
                 c * MOD_CONTROL +
                 s * MOD_SHIFT +
                 w * MOD_WIN;
            desc := ALT[a] + CTRL[c] + SHIFT[s] + WIN[w];
            for h := $41 to $5A do begin
              if RegisterHotKey(0, id, m, h) then begin
                Writeln(desc + Char(h) + ' available');
                UnregisterHotKey(0, id);
              end else if GetLastError = ERROR_HOTKEY_ALREADY_REGISTERED then
                Writeln(desc + Char(h) + ' unavailable')
              else
                Writeln('An error occurred!')
            end;
          end;
    GlobalDeleteAtom(id);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Open in new window

0
 
mccoymadAuthor Commented:
I already had made a Loop that tests all the possibilities of hotkey, but I wanted to make a cleaner routine!
It found that the Windows had a ready command!
0
 
jimyXCommented:
I've been looking around but apparently there is no such clean code.

What is that command that you found ?
0
 
mccoymadAuthor Commented:
All program that captures the screen goes to call the function windows GetWindowDC (GetDesktopWindow), then the part of the code .exe will be equal for all, agrees to me?

I made two programs in Delphi.

The first one uses the function GetWindowDC (GetDesktopWindow) and second hand it does not use the function.

I compared the code .exe of the two programs and more found the following code in the first program:

232, 218, 151, 251,
255, 80, 232, 188,
152, 251, 255, 163,
212, 251, 68, 0

Now I have that to look for inside of other programs that capture the screen, if they possess a part of this code.

It will be that I am certain?
0
 
lomo74Commented:
I feel you are a bit confused.
You want to know which hotkeys are reserved by other applications, right?
Thus... what have GetWindowDC and other GDI functions got to do with your requirements?
And, besides that, what are those numbers?
Tell me you're not trying to interpret CPU instructions that way
0
 
mccoymadAuthor Commented:
I not bit confused!

1º I need to discover if some program in use in the WIndows can copy or this copying the screen of windows
2º I check that the majority of them uses hotkeys, not all, then is not enough to block hotkeys, necessary discovered one another solution

3º Then I verified that to copy the screen ALL the programs need to use the GetWindowDC function

4º Therefore I am looking the instructions of the corresponding processor to the GetWindowDC command

5º If I to discover, resolve my problem because when verifying an open program I check if it uses the instructions of the corresponding processor to the GetWindowDC command

You understood
0
 
lomo74Commented:
I understand that you posted this question:
"How can to discover if has a recorded RegisterHotKey in Windows?"
and now you're pushing 4 more problems that have nothing to do with your question.
So please don't go off topic. Not on EE, if you want to receive help.

Did my and jimyX's posts help you?

You said "It found that the Windows had a ready command!".
Please tell us which is this fabulous command. Remember: we're talking about HOTKEYS not windows' DC or the like.
0
 
mccoymadAuthor Commented:
I finish this topic and I have new topic more especific!
0
 
lomo74Commented:
the author has received two valid answers for his question, which is quite clear indeed.
the fact that, later on, he got confused about his whole project is not a valid reason for deleting this question without assigning points to Experts who took the time to help him.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now