Search code examples
batch-filevbscriptsendkeys

WshShell.SendKeys not working for Alt+Enter


I'm working with a java program which is run in cmd. I have a batch file for starting the cmd and running the program. In it I also run a vbs script which is supposed to send keystrokes Alt+Enter, so the running cmd would go to fullscreen mode. However it doesn't seem to work; I tried sending in Alt+F4 and Alt+Tab and both work just fine, Alt+Enter is the only key combination not working for me.

Here's the batch file:

@echo off
title <title>
CMD /C "cscript fullscreen.vbs && cd <path to program> && java <program>"
exit

And here's the fullscreen.vbs script:

Set ws = WScript.CreateObject("WScript.Shell")
ws.SendKeys "%~"
Set ws = Nothing

I need the cmd to go to fullscreen before or after the program starts, but all it does is it hits Enter once the program is running and waiting for input. I also tried "%{ENTER}" instead of "%~" but no success there either. Also, I'm using windows 10, so Alt+Enter for fullscreen is supported and works fine if I do it on the keyboard.


Solution

  • Well I didn't figure out why Alt+Enter ("%~") doesn't work, however I found out that F11 does the trick so that's what I'm using now.

    ws.SendKeys "{F11}"

    CMD now goes fullscreen before the program starts.