Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-11-19
12
Medium Priority
?
616 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 1336 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 1336 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
Technology Partners: 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!

 
LVL 8

Assisted Solution

by:lomo74
lomo74 earned 664 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
 

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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

722 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