Skip to content

Recommended way to handle keypresses in my script? #299

Closed Answered by tareqimbasher
RThomasHyde asked this question in Q&A
Discussion options

You must be logged in to vote

Not as when dealing with a terminal directly. You can't interact with the script process directly using key input. The only time you can pass it input is when you do Console.ReadLine() and NetPad will give you a place to type your input and it passes it along to the script.

To stop a script abruptly you can use the stop button but if you're looking to use input to stop your loop gracefully you can have a Console.ReadLine() running in a separate thread in your code and when you type 'stop' or something it will set a flag that your infinite loop is checking on every iteration and exits if the flag is set. I haven't tried that scenario within NetPad but I can't think of why it wouldn't work.…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by tareqimbasher
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants