Home Contact

Igor Milovanović

.NET, cats and more...

News

Article Categories

Archives

Post Categories

Image Galleries

Blogs I read

Communities

Links

Syndication:

Mouse Button Swapper – A simple windows 7 Silverlight gadget

 

I am using the mouse with my left hand but I am not swapping the mouse buttons. (Old habit  from the times I was using public workstations at the university. I was too lazy to play with the system setup every time, so that I just moved the mouse from the right to the left side.)

I am also using multiple pointing devices with my notebook. (a gaming mouse with multiple buttons at home, a simpler one at work, and also from time to time the touchpad ). Normally I would setup the mouse button layout in the driver once  for every device . A few months ago however I bought a Roccat Kova gaming mouse. Cool, fast, precise but unfortunately also driverless. Swapping the mouse button layout for Kova and for all other pointing devices started being rather complicated: Click on Control-Panel, Mouse, Swap-Mouse Buttons etc.

After few times I had to do go through the Control Panel, I decided that I had enough of clicking (and I was also in the mood to play around a bit with the technology) so I wrote a small windows 7 gadget in Silverlight which can be used to quickly swap mouse buttons. This way I can just quickly double-click the gadget on the desktop to swap layout, without the need to go to control panel.( I am planning to add some automated device recognition to the gadget in the future, but for now I am pretty much ok with this.)

 

Swapping the mouse buttons under windows is actually a very simple API call:

 

    public static class Win32ApiUtilities
    {
        private static readonly int SM_SWAPBUTTON = 23;
 
        public static bool IsMouseSwapped()
        {
            return GetSystemMetrics(SM_SWAPBUTTON) > 0;
        }
 
        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern int GetSystemMetrics(int nIndex);
 
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool 
            SwapMouseButton([param: MarshalAs(UnmanagedType.Bool)] bool fSwap);
    }

 

The problem with API-calls is that they can’t be done directly from Silverlight (silverlight runs in a sandbox), however there is a workaround :

 

A windows 7 gadget is actually a simple html page with some XML settings zipped and renamed to .gadget file. As Silverlight can communicate with the JavaScript engine of the host page, and the security settings of a gadget allow the browser to instantiate and invoke COM objects, the solution for the invocation of an API call from Silverlight can be done like this: Silverlight –> JavaScript –> COM Interop –> API Call. Not nice but doable. Here are the necessary steps:

 

Create a class and register the assembly for COM Interop:

 
[ComVisible(true)]
[Guid("4C5DE161-3D74-401A-88BF-85F05E2D77AC")]
[ProgId("MouseSwapper.MouseSwapper")]
[ClassInterface(ClassInterfaceType.AutoDual)]
public class MouseSwapper : IMouseSwapper
{
    public void LeftySetting()
    {
        Win32ApiUtilities.SwapMouseButton(true);
    }
}

 

Write a script function  in the gadget HTML page to instantiate the ActiveXObject and invoke the method:

 

<script type="text/jscript">
        function LeftySetting() {
            var mouseSwapper = new ActiveXObject("MouseSwapper.MouseSwapper");
            mouseSwapper.LeftySetting();
        }
</script>
 
And call the script from Silverlight:
 
 
HtmlPage.Window.Invoke("LeftySetting");

 

This is how the gadget looks like:

 

image

image

 

 

 

 

 

If you are left handed and happen to have the same problem like me with your Kova (or any other driverless device) the working version of the gadget is below (You will need .NET Framework 4.0 and Silverlight 4 installed on your machine):

 



Working with Visual Studio Web Development Server and IE6 in XP Mode on Windows 7

 

(Brian Reiter from  thoughtful computing has described this setup in this StackOverflow thread. The credit for the idea is entirely his, I have just extended it with some step by step descriptions and added some links and screenhots.)

 

If you are forced  to still support Internet Explorer 6, you can setup following combination on your machine to make the development for it less painful. A common problem when developing on Windows 7 is that you can’t install IE6 on your machine. (Not that you want that anyway). You will probably end up working locally with IE8 and FF, and test your IE6 compatibility on a separate machine. This can get quite annoying, because you will have to maintain two different development environments where you might not have all needed tools available etc. If you have Windows 7, you can help yourself by installing IE6 in a Windows 7 XP Mode, which is basically just a Windows XP running in a virtual machine.

 

[1] Windows XP Mode installation

 

After you have installed and configured the XP mode (remember the security settings like Windows Update and antivirus software)  you should add the shortcut to the IE6 in the virtual machine to the “all users” start menu. This shortcut will be replicated to your windows 7 XP mode start menu, and you will be able to seamlessly start your IE 6 as a normal window on your Windows 7 desktop.

 

[2] Configure IE6 for the Windows 7 installation

 

If you configure your XP – Mode to use Shared Networking (NAT), you can now use IE6 to browse the sites on the internet. (add proxy settings to IE6 if necessary).

 

image

 

 

 

 

 

 

 

 

  

The next problem you will confront now is that you can’t connect to the webdev server which is running on your local machine. This is because web development server is crippled to allow only local connections for security reasons. In order to trick webdev in believing that the requests are coming from local machine itself you can use a light weight proxy like privoxy on your host (windows 7) machine and configure the IE6 running in the virtual host.

 
The first step is to make the host machine (running windows 7) reachable from the virtual machine (running XP). In order to do that install the loopback adapter and configure it to use an IP which is routable from the virtual machine. 
 

[3] How to install loopback adapter in Windows 7

 

After installation, assign a static IP which is routable from the virtual machine (in example 192.168.1.66)

image

 

 

 

 

 

 

 

 

The next step is to configure privoxy to listen on that IP address (using some not used port) .Change following line in config.txt:

 

#
#      Suppose you are running Privoxy on an IPv6-capable machine and
#      you want it to listen on the IPv6 address of the loopback device:
#
#        listen-address [::1]:8118
#
#
listen-address  192.168.1.66:8118

 

The last step is to configure the IE6 to use Privoxy which is running on your Windows 7 host machine as proxy for all addresses (including localhost)

 

image

 

 

 

 

 

 

 

 

 

 

 

 

And now you can use your Windows7 XP Mode IE6 to connect to your Visual Studio’s webdev web server.

 

image

 

 

 

 

 

 

 

 

 

[4] http://stackoverflow.com/questions/683151/connect-remotely-to-webdev-webserver-exe



.NET Day Franken Community Conference

 

The call for papers for the first franconian .NET community conference is open.

[1] http://www.dotnet-day-franken.de/Sprecher.html

 

 

 

 



.NET UG Franken - Microsoft ASP.NET MVC Framework

Am 23. Juni 2009 ab 19:00 Uhr wird das kommende Treffen der dodned User Group Franken stattfinden.

Der Vortrag von Albert Weinert:

Das ASP.NET MVC Framework

Das ASP.NET MVC ist eine weitere Säule des ASP.NET Framework. Lauffähig ab .net 3.5 bringt es einen anderen Ansatz in die Web-Entwicklung. Seperation-Of-Concerns ist das große Leitbild unter welchem ASP.NET MVC entwickelt worden und und wie man dafür entwickelt.

Gegenüber ASP.NET WebForms ist eine ganz andere Entwicklungsart, dieser Vortrag bringt Ihnen die Vorteile von ASP.NET MVC näher. Es wird erklärt wie es sich in die ASP.NET Pipeline einfügt, wie man eigenen Erweiterungen vornimmt und Web-Anwendungen mit sauberen Prinzipien entwickeln kann.

Ort:

evosoft GmbH
Fürtherstr. 212
D-90429 Nürnberg

Parkplätze gibt es hier (mit Evosoft GmbH ausgeschildert).

 

 

Weitere Informationen:

[1] .NET User Group Seiten http://www.dodned.de
[2] Event Seiten und Anmeldung : http://dodnedderImJuni09.events.live.com/
[3] Blog von Albert Weinert : http://der-albert.com/

 

 

 



Team Conf 2008 in Munich - Agile Software Development with Scrum for Team System

I will speak about agile software development with scrum for team system at the team conf 2008 in munich. The conference is organized in cooperation of hlmc events and german it magazine ix.

[1] http://www.teamconf.de/startseite/
[2] http://www.teamconf.de/anwendervortraege/evosoft-gmbh/