Welcome to Siddharth Hegde's personal, official, globally accessible digital junkyard website & blog. If you would like to know more about me, my life, my work, or just want to stalk me, then you are at the right place. For everything else there is www.google.com

Keyboard remap - Change, disable or remap keys on Windows

June 10th, 2009

The problem: For a long time I have tried various methods to disable the worst key on the keyboard - the CAPS lock. In my opinion, it provides no real function and yet is placed in a position where it can be easily be pressed.

AutoHotKey

Attempt 1: Initially I disabled this key using an AutoHotKey script. But for some reason, the script would stop working and I would still find CAPS LOCK ON just when I was entering that password or something. Besides every new computer I went to needed to have AutoHotKey or a compiled .exe just for this purpose. Since I am fanatical about keeping 24×7 background apps to a minimal, this was a big no no. And finally, even though I think AutoHotKey is a very useful app, I doubt it can be used as a full scale keyboard  remapper.

KeyTweak

Attempt 2: After being pushed over the edge with AutoHotKey’s incompetence in this area, my hunt for a new application continued. After some modified google search terms and fresh hope for luck, I came across KeyTweak, among others which included plain old registry hacking and several incarnations or AutoHotKey. KeyTweak did just what I wanted. Once initial the configuration was made, it would do all the dirty registry hacing for me and I did not need any software to running in the background.

But now I was faced with a new problem, and this time it was caused due to personal circumstances. I had recently moved to a new country and this meant getting used to a whole new keyboard layout just for one new charecter - £. I think you know which country I am talking about. Initially I resisted by opening ‘Character Map’ and copying the £ symbol from the table. But soon I realized that this was happening more often than not and I needed another solution.

Secondly even if I did give in and decide to get used to a new keyboard layout, I’d still be stuck with a US keyboard on my laptop. Changing that would be a fairly expensive affair and if I didn’t it would mean different keyboard layouts on different computers which can get very very irritating. I say this out of experience.

AutoHotKey - Although this could do the job, I was still against having an app running in the background just so that it could type the £ for me. But until I found a better solution, this was going to be the answer to the problem.
KeyTweak - Although this could remap keys to others, somehow it was not able to find the £ character for me.

Microsoft Keyboard Layout Creator

Attempt 3: So once again it was back to google. That is when I found ‘Microsoft Keyboard Layout Creator‘. From the depths of Microsoft’s lair lies this little known app that can do pretty much anything and everything you wanted. Basically you create a whole new keyboard layout, just like the professionals do.

msklc

A quick guide to using Microsoft Keyboard Layout Creator

  1. So once you have done the obvious download and install, run the application.
  2. If you are like me and want to remap change a few keys, then load your current keyboard layout by going to
    File > Load existing keyboard
  3. If you are not sure which keyboard layout you are using, you can find this by going to
    Control Panel > Regional and Language Options > Languages (tab) > Details (button)
  4. Reconfigure the keys to the way you like it
  5. Create a new installation package by going to
    Project > Build DLL and Setup Package
    Follow the instructions and create a installation package. Remember to give it a name that you can identify later.
  6. Install the new layout using the installation package
  7. Go to
    Control Panel > Regional and Language Options > Languages (tab) > Details (button)
    Beside the tree view, click Add… and select the new keyboard layout that you just created.
  8. Activate it by selecting the new layout from the drop down menu where is says
    Default input language
    Alternatively, you can switch between this layout and your old layout by enabling the language bar.

I hope this guide helps you get the most out of your keyboard.

All links are verified to be valid at the time of writing this post. If any of the links in this article or anywhere else on my blog are broken, let me know via the comments and I shall do my best to fix it.


TerminateApp: Close, don’t kill that app

May 11th, 2009

Recently when automating certain tasks, I came across the need for a command line app that would close windows applications in a clean way. After a lot of searching I was surprised not to find something to do this simple task. Yes there a lot of tools to kill an application, but that was not what I was looking for.

Why?
Well, a lot of applications perform a lot of important tasks before they close. These range from saving settings, asking you to save files, releasing hooks. Whatever the task may be, if you killing an application stop it dead in it’s tracks and the app does not have a chance to perform these tasks.

So TerminateApp is the result of this necessity.
You can specify the process by it’s name or by it’s process ID. If you really are impatient, you can even kill the application if the application refuses to terminate within a given amount of time.

How does it work?
TerminateApp sends a WM_QUIT message to all window handles within a specified process. So it will only work for applications that process the WM_QUIT message. This worked fine for the several applications I tested it on, but I cannot guarantee it works on all the apps out there. This would depend on the way the app has been written.

[compress Download TerminateApp]
[page_white_cplusplus Download Source Code]


Vector Texture v1

March 27th, 2009

It’s been some time since anything technical has been posted here. Been spending my time building up a stronger base since the top seemed a little wobbly.

Got a new demo out today. It’s something that some people (including me) call vector textures. A very interesting technique that uses the existing texture resizing methods implemented on the GPU. These days it’s hard to find graphics techniques that manage really makes use of everything the GPU provides us with. What’s even nicer is that this technique could improve existing methods of rendering things like text and could even be extended to rendering blades of grass or leaves on a tree where the possibility of zooming in to a leaf is very real.

Go ahead, read more about it and download the demo here


Chamrajpet Charles

December 10th, 2008

Hey, What you doing child…
Loafing around the internet like a college boy outside a girl’s college.

For those of you who don’t know who Chamrajpet Charles is, I’ll forgive you. If you have not heard of him, I seriously doubt you will be able to fully appreciate this post

For the rest, you will get some upper cuts on your kidneys if you lie only. So for all CC fans out there, here are some rips that will make you feel at home, where ever you are

He makes me laugh no matter what my mood. Feel free to download them to your computer. And now for my track collection…

Read the rest of this entry »


Water you can swim in

October 19th, 2008

Water!!! Water you can swim in… Well only virtually :-) This is my very first graphical demo built on a excellent open source framework called G3D.

Demo is based on two chapters in the ShaderX book.
“Rendering Ocean Water”
by John Isidoro, Alex Vlachos, Chris Brennan
And
“Rippling Refractive and Reflective Water”
by Alex Vlachos, John Isidoro and Chris Oat

Features include

  1. Realtime vertex displacement
  2. Full control over speed, wave direction, amplitude and frequency
  3. Additional detailing via two normal maps
  4. Fake refractions that look real
  5. Real time reflections or reflections via environment maps
  6. Fully configurable water color via texture maps

Welcome to GBuffer.Net 2.0

October 11th, 2008

Faster, cleaner, better…

This upgrade has been long overdue, but there are a lot of other things to consider. The blog is now powered by Wordpress. I did consider a new version of Drupal, but Wordpress seemed a lot cleaner and more widely supported.

Pictures and albums are now on Flickr.com. ImageShack.us was not really managing my gigabytes of pictures too well and my decision to self manage the pictures backfired.

There have been some posts that have been brewing in my head, but have been put off waiting for this upgrade to happen. So now that it has happened, they will see the light of day fairly soon.


Square root without sqrt

March 17th, 2008

A few months back, I was given an interesting project to work on in an interview test. The test required me to build a small particle system for the Nintendo DS, using the homebrew tool chain. Well I don’t know if I was stupid or just plain blind, but I was unable to find a sqrt in their standard math.h include file. Posting questions on a forum resulted in no replies and time was running short. I had only about a week to make my submission. So I decided to write my own implementation. After all I remember doing this in high scool.

The old school method…

As usual I headed over to google and after a little searching I found it on this website. Well this was exactly what I was looking for, but unfortunately it required too much guessing at every step. Now as we all know computers are not good at guessing. All hopes of implementing a square root function quickly evaporated.

Next day in office, with some help from my coleague Ashwini Kumar, we came up with a very promising solution.

We found something interesting about the patterns a square root takes

sqrt(1.0) = 1.0
sqrt(10.0) = 3.1622
sqrt(100.0) = 10.0
sqrt(1000.0) = 31.622

Now for those of you who have not realized yet, sqrt(1000.0) = sqrt(10.0) * 10.0

Well this could work pretty well and all we needed to do then is just generate a look up table of the first 100 numbers and then just do a multiplication based on it’s 10th power. So I came up with this code…

// LUT for square roots below 100. Takes 396 bytes

const static float SQRT_LUT[] =
{
       1.000000f,      1.414214f,      1.732051f,      2.000000f,
       2.236068f,      2.449490f,      2.645751f,      2.828427f,
       3.000000f,      3.162278f,      3.316625f,      3.464102f,
       3.605551f,      3.741657f,      3.872983f,      4.000000f,
       4.123106f,      4.242640f,      4.358899f,      4.472136f,
       4.582576f,      4.690416f,      4.795832f,      4.898980f,
       5.000000f,      5.099020f,      5.196152f,      5.291502f,
       5.385165f,      5.477226f,      5.567764f,      5.656854f,
       5.744563f,      5.830952f,      5.916080f,      6.000000f,
       6.082763f,      6.164414f,      6.244998f,      6.324555f,
       6.403124f,      6.480741f,      6.557438f,      6.633250f,
       6.708204f,      6.782330f,      6.855655f,      6.928203f,
       7.000000f,      7.071068f,      7.141428f,      7.211102f,
       7.280110f,      7.348469f,      7.416198f,      7.483315f,
       7.549834f,      7.615773f,      7.681146f,      7.745967f,
       7.810250f,      7.874008f,      7.937254f,      8.000000f,
       8.062258f,      8.124039f,      8.185352f,      8.246211f,
       8.306623f,      8.366600f,      8.426149f,      8.485281f,
       8.544003f,      8.602325f,      8.660254f,      8.717798f,
       8.774964f,      8.831760f,      8.888194f,      8.944272f,
       9.000000f,      9.055386f,      9.110434f,      9.165152f,
       9.219544f,      9.273619f,      9.327379f,      9.380832f,
       9.433981f,      9.486833f,      9.539392f,      9.591663f,
       9.643651f,      9.695360f,      9.746795f,      9.797959f,
       9.848858f,      9.899495f,      9.949874f,
} ;

float SqrtLUT(const float fNum)
{
     int      nIdx ;
     int      nApproxLog = 0 ;
     float    fCopy = fNum ;
     float    fMultiplier = 1.0f, fDivider = 0.1f ;

     if (fNum < 100.0f && fNum >= 1.0f) // Use LUT

     {
         nIdx = static_cast<int>(fNum) ;
         if (nIdx)
         {
             --nIdx ;
             return SQRT_LUT[nIdx] ;
         }
     }

     // Number is above 100, bring it down and just multiply the answer

     if (fNum >= 100.0f)
     {
         while (fCopy > 1.0f)
         {
             fCopy *= 0.1f ;

             if ((nApproxLog & ~3) && (nApproxLog & 1))
             {
                 fMultiplier *= 10.0f ;
                 fDivider *= fDivider ;
             }

             ++nApproxLog ;
         }
     }
     // Number is below 1. Bring it with in the 1-100 range

     else
     {
         // ...
         // Something very similar to the if block above
         // ...
     }

     return GuessSqrt(fNum * fDivider) * fMultiplier ;
}

This worked really well for numbers under 10^3, but as the numbers grew larger the errors started growing larger and larger. Even a LUT of doubles instead of floats just offset the errors to a slightly larger numbers.

Time to look for a new solution…

The Babylonian Method

A quick recap of old college textbooks revealed a suprising simple method. This method only produces an estimate, but the accuracy of the estimate grows rapidly on every iteration. For those of you who need a quick recap of the algorithm, here is a recap from http://pballew.net/oldsqrt.htm

1) Guess a number for the square root
2) Divide the number by the guess
3) Average the original guess and the new guess
4) make this average value your new guess and
5) Go back to step 2 if the accuracy of the result is not satifactory…

The problem with this method is that it still requires a guess like the old scool method, but this requires a guess only once and the rest of the guesses are relatively small calculations which don’t need any sort of loop. Besides with our LUT method we can now provde a fairly accurate guess relatively fast. So the initial implementation looked something like this…

const static int gIterations 20 ;

float mSqrt(const float fNum)
{
 float x1 ;

 x1 = GuessSqrt(fNum) ; // Just uses the LUT function mentioned above

 for (int i=0; i<gIterations; ++i)
 {
 x1 = ( ( fNum / x1 ) + x1 ) * 0.5f ;
 }
}

After a little trial and error I decided the the number of iterations are best kept at 12.

The end result

Turns out it aint that bad. On my old 1.6Ghz system this implementation is only 0.002 seconds (approximately) slower than sqrt() when calculating 10000 square roots.

My implementation (available in the attachment below) has a much more complicated implentation that does a loop unwind using C++ templates. How else can I justify spending large amounts of time spent trying to understand Andrei’s book, Modern C++ design . As of now that book has become my latest programming fad. :)

You can download the VS.Net 2005 project of my implementation (Attached at the end of this blog entry). The .cpp file has code to check the speed and accuaracy of the results against the standard CRT sqrt function. Most of the code that you should be interested in, is in main.cpp. If you want to use the function in your own project, just copy everything except the main function in main.cpp

Until next time


Download HBO’s new series ‘In Treatment’ from outside the USA

March 9th, 2008

For the impatient… head over directly to the direct download links

For those of you who don't know, HBO recently put the first 15 episodes of their new show 'In Treatment' online. That was good news so the first thing I did was head over there and checkout their 2 min preview. Looked quite interesting, except for the part where the full episodes can't be watched from my country (India), or for that matter any country other than USA [Haven't confirmed this yet].

Now this has got to be one of the lamest attempts to block people from outside USA watching your shows. This is the probably one of the biggest reasons thepiratebay is doing so well. Besides this goes directly against one of my most fundamental beliefs that once information is online anyone in the world should be able to access it. Sure I could catch the episodes on youtube, but then youtube has never been my favorite for offering such low quality videos without giving you a choice. HBOs online stream was much bigger and was on the border line of acceptable. So this is what I wanted and this is what I was going to get.

The first step is to find the .flv files they were linking to. I thought that if I get a direct link to the .flv file I may not have to even watch it online.

Unfortunately I realized that the .flv file was actually a redirect script, to redirect the person based on his IP address. This is another lame attempt to block people. So I just went and found a proxy in USA and managed to get the direct links to the actual .flv file. Turns out that once you have the direct links to the files, you don't even need to be behind a proxy. Might as well make HBO pay for the bandwidth.

In fact even if you are in USA, this will probably be a more convenient method of watching the show, as you can just queue up all the episodes in your favorite download manager and then watch it in your favorite media player.

And before I forget, probably the reason you came here, the…

Direct download links

Laura:
Week 1
Week 2
Week 3

Alex:
Week 1
Week 2
Week 3

Sophie:
Week 1
Week 2
Week 3

Jake and amy:
Week 1
Week 2
Week 3

Paul and Gina:

Week 1
Week 2
Week 3


Quick fix for asynchronous subtitle (.srt) files

February 10th, 2008

So, yesterday I was getting down to watch a relaxing movie and I realized that (yet again), that the SubRip file was not properly synced with the video. I decided that I've had enough of this. It's happened far too many times. So I opened up the .srt file in TextPad and realized everything is right there in plain text. That's probably because M$ or the MPAA did not have a say in the matter. Anyway, so instead of spending 30 mins searching for a new subtitle file on DivxSubtitles or OpenSubtitles I decided to write my own app that will offset the timings in an srt file.

For those of you in a similar situation, I'll save you 30 mins of searching or writing a quick script.
Just click here and follow the instructions on the following page. You should be done in under a minute.


Compile time assertion

January 18th, 2008

Yesterday I finally found a use for compile time checking. I remembered reading this up in Andrei's book 'Modern C++ Design'. So I got down to implementing it in VS.NET 2005.

His code (code below) seemed to work well in theory, but knowing MS, that's as far it goes.

template<bool> struct CompileTimeChecker
{
     CompileTimeChecker(...);
};
template<> struct CompileTimeChecker<false> { };
#define STATIC_CHECK(expr, msg)
     {
          class ERROR_##msg {};
          (void)sizeof(CompileTimeChecker<(expr) != 0>((ERROR_##msg())));
     }

Turns out that MS VS.Net had some complaints about the code above…

error C2066: cast to function type is illegalerror C2070: 'CompileTimeChecker (main::ERROR_ONE_NOT_EQUAL_TO_ONE (__cdecl *)(void))': illegal sizeof operand

At first I thought I’d take the easy way out and just throw an error using a #pragma. But then that would beat the very purpose of the code being compiler independent. After some 30 mins of trial and error, managed to get the same code (code below) working with a few minor modifications.

template<bool> struct CompileTimeChecker
{
     CompileTimeChecker(...){};
};

template<> struct CompileTimeChecker<false> { };

#define STATIC_CHECK(expr, msg)
{
     class ERROR_##msg {};
     ERROR_##msg y ;
     (void)sizeof(CompileTimeChecker<(expr) != 0>((y)));
}

Now calling something like…

STATIC_CHECK(sizeof(char)>sizeof(int), SIZEOF_CHAR_NOT_GT_SIZEOF_INT) ;

will result in a compile time error that looks something like this…

error C2440: '<function-style-cast>' : cannot convert from 'main::ERROR_SIZEOF_CHAR_NOT_GT_SIZEOF_INT' to 'CompileTimeChecker'> No constructor could take the source type, or constructor overload resolution was ambiguous

Until next time, happy coding!