This is very neat, ReFuSeR!
Impressive for your first dialog.
However, you can change some things to make the script work faster and more effectively.
if ($did == 37) {
if (%capslock == 0) {
did -a $dname 1 q
halt
}
if (%capslock == 1) {
did -a $dname 1 Q
halt
}
In this case, luckily, you're preforming two similar commands, /did -a $dname 1, only to change the two values, q or Q.
I would be a little reluctant when using variables in scripts, but it isn't quite necessary. Because $did(37) is a flat button you can use the prefix of .state after the $did(37) and an $iif to really make that part and similar parts shorter.
So the code block in your script can be rewritten as:
if ($did == 37) { did -a $dname 1 $iif($did($v2).state == 1,Q,q) }