Solved

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

Posted on 2010-11-19
12
589 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

21 Experts available now in Live!

Get 1:1 Help Now