Read single key from ISE

Welcome Forums General PowerShell Q&A Read single key from ISE

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 1 month ago.

  • Author
  • #91633

    Points: -17
    Rank: Member

    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

  • #91634

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    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

      Points: -17
      Rank: Member

      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.

The topic ‘Read single key from ISE’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort