Click here to Skip to main content
15,032,967 members
Articles / Desktop Programming / WTL
Posted 24 Aug 2006


28 bookmarked

KDE Mouse Emulator

Rate me:
Please Sign up or sign in to vote.
4.89/5 (26 votes)
30 Sep 2006MIT4 min read
A small application which emulates the behavior of the mouse in KDE

Sample Image - kdemouse.png


This is a small application which emulates the behaviour of the mouse in KDE. It uses global window hooks and WTL.

In KDE (a desktop environment for UNIX operating systems), Windows can be moved and resized without having to click on Window edges or going through menus. To move a Window, simply press ALT and press left mouse button and reposition the Window by moving the mouse. To resize a Window, press the right mouse button instead, and adjust the position of the bottom right corner by moving the mouse.

I chose not to write a lengthy article about this tool mainly because the techniques I have used have already been covered on Code Project and elsewhere. The main technique I utilize is the hooking mechanism provided by Windows. A search for SetWindowsHookEx() will give you plenty of material on that topic. When you start the application, a tray icon will appear. The icon is an image of a typical basic Microsoft mouse with a scroll wheel. You can't miss it. Right click it for Enable, Disable, About and Quit. The provided zip file contains the source code as well as precompiled binaries. The binaries have been compiled in release mode.

The application will only manipulate top level Windows, which have the WS_THICKFRAME style set. Your child Windows and unresizable dialogs are thus safe.

Extra Stuff

New Functionality as of August 25th 2006

  • ALT and scrollwheel up/forward maximizes a Window
  • ALT and scrollwheel down/backward restores a Window
  • ALT and middle mouse button closes a Window (WM_CLOSE is sent)

New Functionality as of August 28th 2006

  • ALT is no longer hard coded. A combination of ALT, CTRL and SHIFT is now configurable
  • Windows being resized or moved may now be activated (raised to foreground), if the application has been configured for that
  • Resizing is now relative to where the mouse cursor is. If you grab the top left corner, the Window will resize by moving that corner. Grab the middle of the top side, and the Window will resize by moving the top edge.

Caveat Emptor

Since I'm using global hooks, antivirus programs may tell you that this application is a trojan. While I assert that it is not, you can check for yourself - the sources are in the zip file. There is a small bug, which you normally don't notice in most apps. Since I "consume" mouse clicks when the ALT-button is pressed, you will not be able to use such combinations in applications. Photoshop is one such application - you will not be able to use the ALT-button as a shortcut for zooming. I am contemplating a partial solution for it though. The plan is to see if the mouse has moved between WM_xBUTTONDOWN and WM_xBUTTONUP. If it has not, I'll regenerate the first mouse WM_xBUTTONDOWN message, followed by WM_xBUTTONUP. This still won't help applications which want ALT + button + mouse move. There is a certain risk of addiction associated with this mouse behaviour. Once you go KDE mouse, you won't go back (unless you're a Photoshop user).

Room For Improvements

There is of course room for improvements. Apart from the "bug" described above, there are many other things one could implement. Configurability comes to mind: key bindings and "ignore lists" (to make the application ignore apps like Photoshop) would be nice. Although I'm satisfied with this application, I'd be delighted to receive enhancements.

Public Domain

This application and its source code is hereby put in the public domain. The icon which comes with the application is however NOT in public domain. I do not own the copyright for it.


I used Robert Edward Caldecott's excellent code for easy handling of tray icons and associated menus. You can find his article here.


  • 2006-08-25: Updated source code per MrARSoft's request: Unmaximize maximized Windows when moved or resized
  • 2006-08-25: Added extra functionality - scroll wheel and middle mouse button
  • 2006-08-28: Configurability
  • 2006-09-30: New feature: Snapping edges. Many thanks to Thomas Freudenberg for this!

Request For Help

When implementing the ability to configure the application at runtime, I discovered unwanted behaviour of shared data segments. It would seem that PODs (plain old datatypes) are initialized once in shared data segments. If I declare int x = 0, x is initialized with the value 0 only once. All other processes which attach to the DLL will see whatever the current state of x is. With non-PODs, you can observe quite a different behaviour. If you declare an object variable in a shared data segment, it seems that the constructor for that object is executed for every attaching thread. It's either that or objects simply aren't shared. If you happen to know what's going on, I would appreciate a message in the message board below.

I did come up with a workaround for this little problem, but it is very inelegant, and I would love to rewrite the code, without having to resort to C-style functions.


This article, along with any associated source code and files, is licensed under The MIT License


About the Authors

Jörgen Sigvardsson
Software Developer (Senior)
Sweden Sweden
I make software.

Thomas Freudenberg
Software Developer Cloud Klabauter GmbH
Germany Germany
No Biography provided

Comments and Discussions

GeneralMinor improvements Pin
Thomas Freudenberg29-Sep-06 13:20
MemberThomas Freudenberg29-Sep-06 13:20 
GeneralRe: Minor improvements Pin
Jörgen Sigvardsson29-Sep-06 13:47
MemberJörgen Sigvardsson29-Sep-06 13:47 
GeneralRe: Minor improvements Pin
Jörgen Sigvardsson30-Sep-06 6:52
MemberJörgen Sigvardsson30-Sep-06 6:52 
GeneralRe: Minor improvements Pin
Thomas Freudenberg30-Sep-06 8:09
MemberThomas Freudenberg30-Sep-06 8:09 
GeneralCould not build in VStudio 2003 Pin
ccm2169-Sep-06 21:02
Memberccm2169-Sep-06 21:02 
GeneralRe: Could not build in VStudio 2003 Pin
Jörgen Sigvardsson9-Sep-06 22:04
MemberJörgen Sigvardsson9-Sep-06 22:04 
GeneralRe: Could not build in VStudio 2003 Pin
ccm21610-Sep-06 23:28
Memberccm21610-Sep-06 23:28 
GeneralRe: Request For Help Pin
PJ Arends1-Sep-06 22:40
professionalPJ Arends1-Sep-06 22:40 
GeneralRe: Request For Help Pin
Jörgen Sigvardsson2-Sep-06 4:44
MemberJörgen Sigvardsson2-Sep-06 4:44 
GeneralExcellent, but... Pin
Rage28-Aug-06 2:44
professionalRage28-Aug-06 2:44 
GeneralRe: Excellent, but... Pin
Jörgen Sigvardsson28-Aug-06 3:55
MemberJörgen Sigvardsson28-Aug-06 3:55 
GeneralRe: Excellent, but... [modified] Pin
Jörgen Sigvardsson28-Aug-06 13:22
MemberJörgen Sigvardsson28-Aug-06 13:22 
GeneralRe: Excellent, but... Pin
Rage29-Aug-06 23:52
professionalRage29-Aug-06 23:52 
QuestionGreat tool Pin
Thomas Freudenberg27-Aug-06 12:11
MemberThomas Freudenberg27-Aug-06 12:11 
AnswerRe: Great tool Pin
Jörgen Sigvardsson27-Aug-06 12:36
MemberJörgen Sigvardsson27-Aug-06 12:36 
AnswerRe: Great tool Pin
Jörgen Sigvardsson28-Aug-06 13:22
MemberJörgen Sigvardsson28-Aug-06 13:22 
GeneralThanks from a KDE developer! Pin
Matt Rogers25-Aug-06 3:42
MemberMatt Rogers25-Aug-06 3:42 
GeneralRe: Thanks from a KDE developer! Pin
Jörgen Sigvardsson25-Aug-06 12:13
MemberJörgen Sigvardsson25-Aug-06 12:13 
GeneralRe: Thanks from a KDE developer! Pin
Matt Rogers12-Oct-06 5:00
MemberMatt Rogers12-Oct-06 5:00 
GeneralRe: Thanks from a KDE developer! Pin
Jeremy Falcon26-Aug-06 5:21
professionalJeremy Falcon26-Aug-06 5:21 
JokeKDE is for girls... Pin
Nemanja Trifunovic25-Aug-06 2:11
MemberNemanja Trifunovic25-Aug-06 2:11 
NewsRe: KDE is for girls... Pin
Anonymuos25-Aug-06 2:21
MemberAnonymuos25-Aug-06 2:21 
JokeRe: KDE is for girls... Pin
Jörgen Sigvardsson25-Aug-06 2:24
MemberJörgen Sigvardsson25-Aug-06 2:24 
GeneralRe: KDE is for girls... Pin
Jim Crafton25-Aug-06 3:49
MemberJim Crafton25-Aug-06 3:49 
GeneralRe: KDE is for girls... Pin
Nish Nishant25-Aug-06 4:50
sitebuilderNish Nishant25-Aug-06 4:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.