Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I hook global shortcuts in Windows?

I remember using a program, some years back, that allowed me to fine-tune my monitor's settings with custom gamma ramps and other adjustments. It had the ability to create different screen-settings profiles for different uses, and setup global hotkey shortcuts to activate them without switching out of the program you're in.

My question is, how do you set up the hook for that? I'm sick of WINDOWS-D minimizing everything when I only want access to the desktop in one screen and I want to keep working in the other one. (I have 2 monitors for a reason!) So I figure it shouldn't be that difficult to hack up a little Delphi app that will minimize everything on one monitor. The only problem is hooking it to a hotkey. Does anyone know what the API is for this?

like image 1000
Mason Wheeler Avatar asked Jan 21 '09 21:01

Mason Wheeler


People also ask

How do I set up hotkeys on Windows?

To assign a keyboard shortcut do the following: Begin keyboard shortcuts with CTRL or a function key. Press the TAB key repeatedly until the cursor is in the Press new shortcut key box. Press the combination of keys that you want to assign.

What are global hotkeys?

A global hot key is associated with a particular nonchild window. It allows the user to activate the window from any part of the system. An application sets a global hot key for a particular window by sending the WM_SETHOTKEY message to that window.


1 Answers

http://www.swissdelphicenter.ch/torry/showcode.php?id=147

Basically there are three steps:

Register

// Register Hotkey Win + A
id1 := GlobalAddAtom('Hotkey1');
RegisterHotKey(Handle, id1, MOD_WIN, VK_A);

Handle

procedure WMHotKey(var Msg: TWMHotKey); message WM_HOTKEY;

{ .... }

// Trap Hotkey Messages
procedure TForm1.WMHotKey(var Msg: TWMHotKey);
begin
  if Msg.HotKey = id1 then
    ShowMessage('Win + A pressed !');

Unregister

UnRegisterHotKey(Handle, id1);
GlobalDeleteAtom(id1);
like image 76
Jim McKeeth Avatar answered Sep 25 '22 08:09

Jim McKeeth