Ryan
Ryan

Reputation: 53

Batch Keystroking

I am making a text-based game in Batch, and I was wondering if you can complete a task if the player presses the Up Arrow Key? I have looked through the help files, and did a Google search, but with no solutions. I can't install any extra software because I use a Windows RT device. Also, if it cannot be done in Batch, can it be done in VBS or Powershell?

Upvotes: 4

Views: 229

Answers (3)

DecstarG
DecstarG

Reputation: 1

You could simply use:

choice /c wsad /n /m "Press a key."

And: if %errorlevel%==1 to detect w and %errorlevel%==2 to detect s and so on

That is a simple way to detect a key being pressed. You can't use batch alone to do this task. You can however use Powershell. Also, if you are on Windows RT you need to update. Get a new PC probably is better.

Upvotes: -1

jeb
jeb

Reputation: 82267

It can be done with powershell, this can also detect the arrow keys.

powershell "$key = [Console]::ReadKey($true);Write-Host $key.key;"

And this can even detect the control keys

powershell "$key = $host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown'); Write-Host "key= $key.VirtualKeyCode";"

Upvotes: 5

Ilya
Ilya

Reputation: 4689

You can use Powershell for it, see example on SO. I am not sure it is possible to process key presses without external programs.

Upvotes: 1

Related Questions