The only way you can possibly achieve "checking while the user types" is if you use "raw" input methods. Unfortunately, that's non-trivial, and depends on the actual system you are running on - it's COMPLETELY different for Windows and Linux, and slightly different from Linux if you are using, say, MacOS or Solaris.
The principle of "raw" input is that the line-editing and buffering is turned off, and the application will get every character as it is typed, instead of "cooked" mode where the data is held in a buffer until the user hits enter.
I'm sure a bit of googling will allow you to find how to do it on your OS - searching for "How to read input without enter on -insert-OS-here" should do it.
Beware however that you will most likely have to deal with all the line-editing - e.g. hitting backspace will just send "backspace" to your program, not erase the last typed character. Backspace is one of my "most hit keys"...
Then all you need is a state machine to track where you are in the sequence of t, o, g and o and set a flag when you hit the o after g. If something else comes in between those characters, obviously the state machine needs to restart.