Toggle caps lock programmatically using applescript

I’m looking to toogle capslock programmatically using applescript. Here is something I tried to make it work. It seems to work for all other keys except capslock.

tell application "System Events"     key code 57 end tell 

57 is the key code for caps lock