[...] how would I make it loop whilst other functions have been called
If I understand you correctly then you want to check for someone pressing ESC
while other functions are running, yes?
If so, then what you want are coroutines. Computercraft has a built-in function to let functions run in parallel, succinctly called "parallel".
Type "help parallel" for info.
Explanation:parallel.waitForAny( function1, function2, … )As the name suggests, it runs all the provided functions in (quasi-)parallel, waiting for
any of them to end.
parallel.waitForAll( function1, function2, … )This one on the other hand waits for all functions to end.
Try it with something simple first to wrap your head around it, like making two functions that run in a loop, waiting for a key to be pressed.
Have one function print some text A on a key-press and the other function print some other text B on a key-press, etc.
Then provide both their names to one of the two parallel-functions and see what happens.^^
As for being able to run something when someone presses ESC: Sure that works, just like you figured with listening for key 1.
In your code though you don't need to check if
k == "key", since you're already filtering for "
key" events (i.e. you've provided
os.pullEvent() with that filter already).