OS X messes up my Bluetooth keyboard modifier keys sometimes, and I wanted a quick solution to the problem.
After a quick Google search, I found this post on Apple Support Communities. It is from 2006 which means it probably was made for OS X 10.4 Tiger. When trying the script on my Mac Mini with 10.8 Mountain Lion a few errors occured and since I thought I would share the updated script with you.
Note: You need UI scripting enabled for this to work. The script disables Caps Lock, sets Alt key to Command and Win key to Option so you can use a Windows keyboard painlessly with native OS X keyboard layout.
You can download the updated script directly from pastebin above or from this link (Dropbox).