@teastain Thank you - I had misunderstood what the Z was for. Because on the ky040 the middle pin is for the "switch" functionality (i.e. pushing down on the encoder) I assumed it was for this. I realise now that I need to treat that as a button and take it off to a different pin, which I know how to do.
Thanks for your help!