You don't need "For each key" if you know the key name. Basically, you can remove events 57-59, except for "set x to n" action.
If the key name is in the frame vairable, to subtract from this key simply use this action:
Dictionary set frame to value (self.get(frame)-x)
If you want it to not drop below zero:
Dictionary set frame to value max((self.get(frame)-x), 0)