如何使用Windows批处理脚本每1秒更改cmd的文本颜色

问题描述 投票:0回答:10

颜色命令与更改 Windows 命令提示背景/文本的颜色有关

颜色 0A - 其中 0 是背景颜色,A 是文本颜色

我想使用带有 1,2,3,4,5,6,7,8,9,A,B,C,D,E,F 的数组在 Windows 批处理脚本中每 1 秒更改这些文本的颜色是颜色代码。

0 = Black       8 = Gray
1 = Blue        9 = Light Blue
2 = Green       A = Light Green
3 = Aqua        B = Light Aqua
4 = Red         C = Light Red
5 = Purple      D = Light Purple
6 = Yellow      E = Light Yellow
7 = White       F = Bright White

命令应该像这样每秒执行一次

color 01
color 02
color 03
....
color 0E
color 0F

对于这些,我找到了一些小脚本,但我不知道如何让它每 1 秒改变一次颜色!

for /L %%i in (1,1,%n%) do echo !array[%%i]!

或者这个

@echo off CLS
for /l %%a in (15,-1,1) do (
color 0A
cls
)
pause

或者这个

SET COUNTDOWN=15
:COUNTDOWNLOOP
IF %COUNTDOWN%==0 GOTO END
color 0A && %R1%
CLS
SET /A COUNTDOWN -=1
GOTO COUNTDOWNLOOP
:END
cmd batch-file
10个回答
36
投票

这应该符合要求。听起来像是一件超级烦人的事情,但你已经看到了:

@echo off
set NUM=0 1 2 3 4 5 6 7 8 9 A B C D E F
for %%x in (%NUM%) do ( 
    for %%y in (%NUM%) do (
        color %%x%%y
        timeout 1 >nul
    )
)

4
投票

尝试这个脚本。这可以在屏幕的任何位置写入任何文本,并且不使用临时文件或“.com、.exe”可执行文件。只需确保您在 windows\system 或 windows\system32 文件夹中有“debug.exe”可执行文件即可。

http://pastebin.com/bzYhfLGc

@echo off
setlocal enabledelayedexpansion
set /a _er=0
set /a _n=0
set _ln=%~4
goto init


:howuse ---------------------------------------------------------------

    echo ------------------
    echo ECOL.BAT - ver 1.0
    echo ------------------
    echo Print colored text in batch script
    echo Written by BrendanLS - http://640kbworld.forum.st
    echo.
    echo Syntax:
    echo ECOL.BAT [COLOR] [X] [Y] "Insert your text"
    echo COLOR value must be a hexadecimal number
    echo.
    echo Example:
    echo ECOL.BAT F0 20 30 "The 640KB World Forum"
    echo.
    echo Enjoy ;^)
    goto quit

:error ----------------------------------------------------------------

    set /a "_er=_er | (%~1)"
    goto quit

:geth -----------------------------------------------------------------

        set return=
        set bts=%~1

:hshift ---------------------------------------------------------------

        set /a "nn = bts & 0xff"
        set return=!h%nn%!%return%
        set /a "bts = bts >> 0x8"
        if %bts% gtr 0 goto hshift
        goto quit

:init -----------------------------------------------------------------

    if "%~4"=="" call :error 0xff

    (
        set /a _cl=0x%1
        call :error !errorlevel!
        set _cl=%1
        call :error "0x!_cl! ^>^> 8"
        set /a _px=%2
        call :error !errorlevel!
        set /a _py=%3
        call :error !errorlevel!
    ) 2>nul 1>&2

    if !_er! neq 0 (
        echo.
        echo ERROR: value exception "!_er!" occurred.
        echo.
        goto howuse
    )

    set nsys=0123456789abcdef
    set /a _val=-1

        for /l %%a in (0,1,15) do (
                for /l %%b in (0,1,15) do (
                        set /a "_val += 1"
                        set byte=!nsys:~%%a,1!!nsys:~%%b,1!
                        set h!_val!=!byte!
                )
        )

    set /a cnb=0
    set /a cnl=0

:parse ----------------------------------------------------------------

    set _ch=!_ln:~%_n%,1!
    if "%_ch%"=="" goto perform

    set /a "cnb += 1"
    if %cnb% gtr 7 (
        set /a cnb=0
        set /a "cnl += 1"
    )

    set bln%cnl%=!bln%cnl%! "!_ch!" %_cl%
    set /a "_n += 1"
    goto parse

:perform --------------------------------------------------------------

    set /a "in = ((_py * 160) + (_px * 2)) & 0xffff"
    call :geth %in%
    set ntr=!return!
    set /a jmp=0xe


    @for /l %%x in (0,1,%cnl%) do (
        set bl8086%%x=eb800:!ntr! !bln%%x!
        set /a "in=!jmp! + 0x!ntr!"
        call :geth !in!
        set ntr=!return!
        set /a jmp=0x10
    )

    (
    echo.%bl80860%&echo.%bl80861%&echo.%bl80862%&echo.%bl80863%&echo.%bl80864%
    echo.q
    )|debug >nul 2>&1

:quit

1
投票

我创建了一种简单的方法来做到这一点,并使其尽可能简单。 最后的“暂停”处是您继续编写代码的地方。 Picture of executed Code

# [CODE]        [DESCRIPTION]
#
# echo. &       starts a new line
# echo.         skips a line
# PainText 08       08 is color code for gray   Type "color ?" for color codes
# " Red"        The space befor text gives space between the word befor it


@echo off
cls && color 08

for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (set "DEL=%%a")


<nul set /p=""
call :PainText 08 "Gray"
call :PainText 04 " Red"
call :PainText 02 " Green"
call :PainText 08 " Gray"
echo. &
call :PainText 02 "Line 2 Green No space"
echo. &
echo.
call :PainText 01 "H"
call :PainText 02 "E"
call :PainText 03 "L"
call :PainText 03 "L"
call :PainText 05 "O"
echo.


goto :end

:PainText
<nul set /p "=%DEL%" > "%~2"
findstr /v /a:%1 /R "+" "%~2" nul
del "%~2" > nul
goto :eof

:end
echo.

pause

1
投票

我正在做一些非常相似的事情。我刚刚开始编码,所以这可能不是最有效的方法,但这就是我的做法:

@ECHO OFF
ECHO HELLO
ping localhost -n 1 >nul
cls
color 01
ECHO HELLO
ping localhost -n 1 >nul
cls
color 02
ECHO HELLO 

等等。


0
投票
echo off & cls
set NUM=0 1 2 3 4 5 6 7 8 9 A B C D E F
for %%y in (%NUM%) do ( 
    for %%x in (%NUM%) do (
        color %%y%%x & for /l %%A in (1,1,200) do (dir /s)
        timeout 1 >nul
    )
)
pause

0
投票

如果它对某人有帮助,我受到了 John Kens 的回答的启发,我在下面编写了一个可以从另一个批处理文件调用的修改版本,如下所示:

rem Put this in your favourite batch file.
call output-coloured-message 02 "SUCCESS!"

从命令提示符处调用它,不带任何参数来获取 USAGE,以提醒您如何使用它。

@echo off

rem ----------------------------------------------------------------
rem File Name: output-coloured-message.bat
rem ----------------------------------------------------------------

for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (set "DEL=%%a")

<nul set /p=""

if "%1"=="" goto :usage

call :PainText %1 %2

goto :end

:PainText
<nul set /p "=%DEL%" > "%~2"
findstr /v /a:%1 /R "+" "%~2" nul
del "%~2" > nul
goto :eof

:usage
@echo.
@echo USAGE: %~n0 xx "My Message"
@echo.
@echo   Examples:
@echo.
@echo   %~n0 04 "We ran into a problem."
call :PainText 04 "  We ran into a problem."
@echo.
@echo   %~n0 02 "SUCCESS!"
call :PainText 02 "  SUCCESS!"
@echo.
@echo.
@echo   type color ? for a list of colours.
@echo   type colour to restore the default.
goto :end

:end


-1
投票
echo off & cls
title   never buy these they're so easy to make... hmu for source code             

    -%pinging:IP%-
color 0D

echo =================================================================
echo i flex on my unhittable ovh, you flex on an easy to hit trash ovh
echo =================================================================
set /p IP=Enter IP:
:top
title :: this skid's boutta get slammed FeelsGoodMan ::    -%pinging:IP%-
PING -n 1 %IP% | FIND "TTL="
IF ERRORLEVEL (echo stop flexing on ovh's i down them with ease, mine on the other hand is unhittable.):
set /a num=(%Random%%%9)+1
color %num%IP   ping -t 2 0 10 127.0.0.1 >nul
GoTo top

这是一个 ip ping,它具有自定义的超时消息,如果某个网站或服务器出现故障,也可以用于引导人们离线,我可以制作一个工具,根据您的输入打开文件和单个 pingers,和内置的地理位置工具。


-2
投票
@echo off
set NUM=0 1 2 3 4 5 6 7 8 9 A B C D E F 31 32 33 34 35 36 37 41 42 43 44 45 46 90 91 92 93 94 95 96 97 100 101 102 103 104 105 106 107 
for %%x in (%NUM%) do ( 
    for %%y in (%NUM%) do (
        color %%x%%y
cls
echo Himel Sarkar
        timeout 1 >nul
    )
)

pause

-3
投票

尝试这个命令:

@echo off
cls
:loop
echo RAINBOW
color 0
echo RAINBOW
color 1
echo RAINBOW
color 2
echo RAINBOW
color 3
echo RAINBOW
color 4
echo RAINBOW
color 5
echo RAINBOW
color 6
echo RAINBOW
color 8
echo RAINBOW
color 9
echo RAINBOW
color A
echo RAINBOW
color B
echo RAINBOW
color C
echo RAINBOW
color D
echo RAINBOW
color E
echo RAINBOW
goto loop

这应该会创建循环变色文本。
编辑:您可以将彩虹一词更改为您想要的任何内容。


-4
投票

在特定计算机上,可以通过在 cmd 窗口属性中编辑颜色值来将颜色代码分配给不同的 RGB 颜色。轻松单击调色板上的颜色并更改其 RGB 值。

© www.soinside.com 2019 - 2024. All rights reserved.