What do you mean by press a key accordingly ? It sounds like you want the computer to detect the change and then press a key but since computers can't really press a key, I don't think that's what you really meant. I'm thinking you meant simulating a key press. Please clarify.

Also why do you want to detect a change on the screen. I can think of one way to do that but its terribly in-efficient and I can't really think of a practical use for such a function.