terminating script with hotkey - concept - doable?

If I create an infinite loop that performs something, and run the script - is there a way to quit that loop by pressing some (user defined or system defined) key? In my scripts, I’m assuming, that both - mouse (via 3rd party app?) and keyboard shortcuts will be in use in a form of stresstest, so this complicates things a little bit.

On the internet, I see some people struggle with the same topic, but there is no clear answer to that issue. In case that monitoring for “key pressed” is not possible in applescript directly - can this be done in some other way?

I came to an Idea that it could be done like this:

  1. Script starts an application, that is running in the background. The purpose of this 3rd party app would be to check if certain key combination is pressed, and if so - certain action is taken. In this case - I guess it would be to quit the script editor (kill the process) in order to stop/quit the script, and maybe quit some other 3rd party processes. Is there such app?

  2. Script performs other tasks, using infinite loop (stresstest that works for hours).

  3. If certain key is pressed, script editor stops or quits, thus the script is being terminated.

p.s.: sorry for my english; please move this topic to correct subform if I write in the wrong one.