Create a variable to store which keystroke you want to type

This actually works for me -- BBEdit will type "zzz" and "ZZZ" as expected. Did you, perhaps, change the value of "thisKey" for the sake of the example? If not, why obfuscate your own code by using key codes rather than characters?

What are you actually trying/expecting to type, and with what modifier(s), in what application?