Search code examples
windowscmdcommand-lineautohotkey

How to clear screen in Windows command prompt window with a hotkey?


I have searched a lot to find a way (keyboard shortcut) to clear the screen of the console window of cmd on Windows 10. I tried Ctrl+L and Ctrl+K and ESC, but nothing worked for me and I didn't find any satisfied solution.

Thanks a lot for the AutoHotkey script.
I modified the script to input Python script to clear the screen when using scrapy shell like that

Send from os import system{Enter}
Send cls = lambda: system)'cls'({Enter}
Send cls)({Enter}

It worked well but I noticed the value 0 at the top of the window.

The console window after execution of AutoHotkey script with as blinking caret symbol.

0
>>> █

How can I remove that zero?


Solution

  • The simplest way of clear window in command prompt is typing: cls + enter

    Ecs is a key to exit input of command prompt, it does noting on clear window

    Ctrl + L and Ctrl + K are not correct short key in Linux command prompt. If you really want to make it a short cut key of cls, you can use AutoHotKey to write a short script

    ; -------------------------------------------------------------------------
    ; Cntr-L should clear screen
    ; -------------------------------------------------------------------------
    #IfWinActive ahk_class ConsoleWindowClass
    ^L::
    Send cls{Enter}
    return
    
    #IfWinActive

    Official website of autohotkey: https://www.autohotkey.com/

    Windows 10 + python 3.9 clear command prompt script: import os os.system('cls')