Click here to Skip to main content
12,818,664 members (29,109 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 19 Apr 2009

Keys Extender (Win 7 Compatible)

, 21 Apr 2009 GPL3
Rate this:
Please Sign up or sign in to vote.
Work with Windows by hot keys in Vista like Windows 7


In Windows 7, I really liked an opportunity to change the position of the windows by pressing hotkeys Win + (Left | Right | Up | Bottom):

  • Win + Left - window attached to the left side
  • Win + Right - window attached to the right side
  • Win + Up - window is maximized
  • Win + Bottom - window in the normal state


Using the Code

Making this work with Windows Vista (most likely will work in earlier versions, but I have not tried it) was not a difficult task. First of all, I imported many WinApi functions in a WinForms application. The work was divided into two parts:

  1. interception of pressing the keys, and
  2. positioning the active window

The art Low-Level Keyboard Hook in C # helped me to solve the first part. I had only to find the way to know whether the button LWin is pressed. Here is the main code:

private static IntPtr HookCallback(
    int nCode, IntPtr wParam, IntPtr lParam)
    if (nCode >= 0 && wParam == (IntPtr)WAKeysHook.WmKeyDown)
        if ((int)WAKeysHook.GetAsyncKeyState((IntPtr)Keys.LWin) != 0) // Left Win Key
            Keys key = (Keys) Marshal.ReadInt32(lParam);
            if (key == Keys.Left || key == Keys.Right || 
		key == Keys.Up || key == Keys.Down) // Arrows keys
    return WAKeysHook.CallNextHookEx(WaKeysHook.HookId, nCode, wParam, lParam);

The second part: looking for the foreground window, setting state and size.

private static void SetWindowLocation(Keys k)
    //Active Window
    IntPtr window = WAWindows.GetForegroundWindow();
    // Check SIZEBOX Style (Window can sizable)
    if (((int)WAWindows.GetWindowLongPtr(window, WAWindows.GwlStyle) & 
        == WAWindows.WsSizebox)
        // Show window in normal state (if always maximized)
        WAWindows.ShowWindow(window, (int)WAWindows.WindowShowStyle.ShowNormal);
        //Need Maximized
        if (k != Keys.Down)
            WAWindows.ShowWindow(window, (int)WAWindows.WindowShowStyle.ShowMaximized);

            // Place Window on left or right
            if (k != Keys.Up)
                WAWindows.Rect rect, rectDesktop;
                if (WAWindows.GetWindowRect(window, out rect) && 
		out rectDesktop))
                    WAWindows.SetWindowPos(window, WAWindows.HwndTop, 
			(k == Keys.Left) ? Math.Min(rect.Left, 0) : 
			rectDesktop.Right / 2, rect.Top, Math.Min(rect.Width, 
			rectDesktop.Right / 2 - Math.Min(rect.Left, 0)),
                                 Math.Min(rect.Height, rectDesktop.Bottom), 

In addition, there is an opportunity to display (or hide) the icon in the taskbar with context menu (that can help you to close the application). You can set these options in app.config  section "ShowNotifyIcon".

        <setting name="ShowNotifyIcon" serializeAs="String">

Enjoy it!    


  • 20.04.2009 - Build version for x64 system
  • 21.04.2009 - Project has new version. Now you can choose the setting, and some bugs fixed. This is the new version window:

You can download the new version and code from here.


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Software Developer (Senior)
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 21 Apr 2009
Article Copyright 2009 by outcoldman
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid