Solved

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

Posted on 2010-11-19
12
592 Views
Last Modified: 2012-05-10
How can to my application Delphi discover if has RegisterHotKey recorded for another program?
0
Comment
Question by:mccoymad
  • 5
  • 4
  • 3
12 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 334 total points
ID: 34174553
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
 

Author Comment

by:mccoymad
ID: 34176245
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
 
LVL 24

Assisted Solution

by:jimyX
jimyX earned 334 total points
ID: 34179183
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
 
LVL 8

Assisted Solution

by:lomo74
lomo74 earned 166 total points
ID: 34179620
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
 

Author Comment

by:mccoymad
ID: 34179883
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
 
LVL 24

Expert Comment

by:jimyX
ID: 34193783
I've been looking around but apparently there is no such clean code.

What is that command that you found ?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:mccoymad
ID: 34195720
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
 
LVL 8

Expert Comment

by:lomo74
ID: 34195912
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
 

Author Comment

by:mccoymad
ID: 34197303
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
 
LVL 8

Expert Comment

by:lomo74
ID: 34197537
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
 

Author Comment

by:mccoymad
ID: 34197814
I finish this topic and I have new topic more especific!
0
 
LVL 8

Expert Comment

by:lomo74
ID: 34197939
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now