detect lock and unlock