input detection logic