A new chemosensor which can detect Hg2+ in water and Hg2+/Cu2+ in acetonitrile and its application as a molecular keypad lock using Cu2+ and Fâ as ionic inputs are demonstrated.