Click here to Skip to main content
Click here to Skip to main content

KDE Mouse Emulator

, , 30 Sep 2006
Rate this:
Please Sign up or sign in to vote.
A small application which emulates the behavior of the mouse in KDE

Sample Image - kdemouse.png

Introduction

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.

References

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

Updates

 

  • 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Authors

Thomas Freudenberg
Architect Pharmatechnik GmbH & Co. KG
Germany Germany
No Biography provided
Follow on   Twitter   Google+   LinkedIn

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

Comments and Discussions

 
GeneralMinor improvements PinmemberThomas Freudenberg29-Sep-06 13:20 
GeneralRe: Minor improvements PinmemberJörgen Sigvardsson29-Sep-06 13:47 
GeneralRe: Minor improvements PinmemberJörgen Sigvardsson30-Sep-06 6:52 
GeneralRe: Minor improvements PinmemberThomas Freudenberg30-Sep-06 8:09 
GeneralCould not build in VStudio 2003 Pinmemberccm2169-Sep-06 21:02 
GeneralRe: Could not build in VStudio 2003 PinmemberJörgen Sigvardsson9-Sep-06 22:04 
GeneralRe: Could not build in VStudio 2003 Pinmemberccm21610-Sep-06 23:28 
GeneralRe: Request For Help PinmemberPJ Arends1-Sep-06 22:40 
GeneralRe: Request For Help PinmemberJörgen Sigvardsson2-Sep-06 4:44 
GeneralExcellent, but... PinmemberRage28-Aug-06 2:44 
GeneralRe: Excellent, but... PinmemberJörgen Sigvardsson28-Aug-06 3:55 
GeneralRe: Excellent, but... [modified] PinmemberJörgen Sigvardsson28-Aug-06 13:22 
GeneralRe: Excellent, but... PinmemberRage29-Aug-06 23:52 
QuestionGreat tool PinmemberThomas Freudenberg27-Aug-06 12:11 
AnswerRe: Great tool PinmemberJörgen Sigvardsson27-Aug-06 12:36 
AnswerRe: Great tool PinmemberJörgen Sigvardsson28-Aug-06 13:22 
GeneralThanks from a KDE developer! PinmemberMatt Rogers25-Aug-06 3:42 
GeneralRe: Thanks from a KDE developer! PinmemberJörgen Sigvardsson25-Aug-06 12:13 
GeneralRe: Thanks from a KDE developer! PinmemberMatt Rogers12-Oct-06 5:00 
GeneralRe: Thanks from a KDE developer! PinmemberJeremy Falcon26-Aug-06 5:21 
JokeKDE is for girls... PinmemberNemanja Trifunovic25-Aug-06 2:11 
NewsRe: KDE is for girls... PinmemberAnonymuos25-Aug-06 2:21 
JokeRe: KDE is for girls... PinmemberJörgen Sigvardsson25-Aug-06 2:24 
GeneralRe: KDE is for girls... PinmemberJim Crafton25-Aug-06 3:49 
GeneralRe: KDE is for girls... PinstaffNishant Sivakumar25-Aug-06 4:50 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 30 Sep 2006
Article Copyright 2006 by Thomas Freudenberg, Jörgen Sigvardsson
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid