Alter the single modifier code to use device independent key masks as opposed to key codes

Fixes #1712
add brackets round ternary operator