Read single key from ISE

Hi all,

I have a small snippet that will read a key if available (rather than wait for a key press)

If ([console]::KeyAvailable) {If (([System.Console]::ReadKey($True)).Key  -Match "F12") {Break} }

The problem is that it does not work with the ISE, it throws an exception

Cannot see if a key has been pressed when either application does not have a console or when console input has been redirected from a file. Try Console.In.Peek.

Does anyone know how to get this to work with the ISE? I can’t seem to get it or any other method to work.

Thanks in advance
Tim

ISE isn’t a console, and so it can’t respond to that. The ISE is meant as a development environment, not a place where you routinely run scripts. I don’t even test in the ISE; I test in the console, because that’s the first-class runtime environment. Heck, I don’t even -code- in the ISE anymore, I use VS Code.

Thanks Don, I appreciate it. I thought that there was little chance the ISE could do this. The only time I use the ISE these days is when I am in a pinch on site. You are right, if you are doing any work with PowerShell, you should be using VSCode. ISE has a much depreciated role these days.