Toggle the Multi Monitor Setting in Windows XP

Introduction

If you use Windows XP and a dual monitor, this article will be helpful for you.

Background

It is a known fact that using multiple monitors can help improve your productivity. Some people find it confusing when using more than one monitor - this article is not meant for them. You can dock, let's say, your email client/calendar on one monitor and your source code editor (Eclipse) on the other one. Or you can dock your music player on one monitor and the article you are pretending to read on the other.

Using the Code

The code is a complete application packaged into a single class file. All you have to do to use the code is:

 java MultiMon

A brief explanation of how the code achieves the desired result is discussed below:

  1. First the display panel is launched using:

     Runtime.getRuntime().exec("control.exe desk.cpl,@0,3");

    This will also cause the third tab in the display control panel to be selected.

  2. Create an instance of the java.awt.Robot class - this class will help us send the desired key strokes to the display control panel.

  3. We then use...

    robot.keyPress(KeyEvent.VK_D + KeyEvent.ALT_MASK);

    ... to send keystrokes, as in the case above ALT+D to the display control panel. And so on...

  4. The keystrokes the code sends out is the same as the ones that you would use if you were to use the keyboard only to toggle the monitor.

  5. Invoke the program using the batch file or compile the source code and run the generated class file.

Note - For ease of use, the class is not included in any package, but is in the default package. However it is a recommended approach to always use packages for the classes.

Of course, you need to make sure that JDK is installed on your machine.

Points of Interest

  1. Ideally, you would like to implement such an application in a Win32 technology using Windows API to achieve the necessary result. But then, I've just used Java...
  2. I just learnt how lazy I can get and I'm not the only one looking at the Google results for the requests for such a solution. I spent less than an hour researching and writing this code. In case you have any positive comments, I'd be glad to hear them.

History

  • 16th April, 2008: Article created

License

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

About the Author

Imran Ebrahim


Imran is a software professional with 9 years of development experience and has worked on JAVA, VB6, VC6, C# & some JavaScript.

He is interested in Hi-Performance code, OO Methodology, OS API's, Optimizing Windows, Tweaking IE.

For the last few years Imran has specialized in developing robust, hi-performance applications & GUI's (Swing) for MNC's. He is currently working with a SAN company.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值