Read single key from ISE

This topic contains 2 replies, has 2 voices, and was last updated by  TeeStar 1 month ago.

  • Author
    Posts
  • #91633

    TeeStar
    Participant

    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

  • #91634

    Don Jones
    Keymaster

    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.

    • #91649

      TeeStar
      Participant

      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.

You must be logged in to reply to this topic.