标题: [游戏娱乐] 批处理本机多进程通信和局域网通信,无第三方,无临时文件 [打印本页]
作者: Blitz 时间: 2023-8-24 13:51 标题: 批处理本机多进程通信和局域网通信,无第三方,无临时文件
本帖最后由 老刘1号 于 2023-9-16 12:00 编辑
就是靠waitfor来传递
发送.bat- @echo off
- for /f %%a in ('echo prompt $H^|cmd') do set "bs=%%a"
- title 发送
- :1
- set "key="
- for /f "delims=" %%a in ('xcopy /w . 2^>nul') do if not defined key set "key=%%a"
- set key=%key:~-1%
- if "%key%" == "" (
- echo=
- set key=enter
- ) else if "%key%" == "%bs%" (
- <nul set/p=%bs% %bs%
- set key=backspace
- ) else if "%key%" == " " (
- <nul set/p=_%bs%
- set key=space
- ) else <nul set/p=%key%
- >nul waitfor /si %key%
- goto 1
复制代码
接收.bat- @echo off
- for /f %%a in ('echo prompt $H^|cmd') do set "bs=%%a"
- title 接收
- if not "%1" == "" goto a
- for %%a in (0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z enter backspace space) do start /b "" "%~f0" %%a
- pause>nul
- exit
-
- :a
- >nul waitfor %1
- if "%1" == "enter" (
- echo=
- ) else if "%1" == "backspace" (
- <nul set/p=%bs% %bs%
- ) else if "%1" == "space" (
- <nul set/p=_%bs%
- ) else <nul set/p=%1
- goto a
复制代码
不过只支持英文、退格、空格、回车,上面的代码还没写标点符号,可以自己加
写到一个窗口里,用了终端控制符,临时赶出来的,比较潦草杂乱:- @echo off
- title demo
- mode 60,40
- rem 读的初始位置
- set r_h=3
- set r_l=15
- rem 写的初始位置
- set response_w=22;15
-
- for /f %%a in ('echo prompt $H^|cmd') do set "bs=%%a"
- for /f %%a in ('echo=prompt $E^|cmd') do set "esc=%%a"
-
-
- if not "%1" == "" goto a
- echo=加载中....
- for %%a in (0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z enter backspace space) do start /b "" "%~f0" %%a&&ping 127.1 /n 1 >nul
- cls
- ping 127.1 /n 2 >nul
- set/pa=%esc%[20;1H<nul
- echo=============================================================
- set/pa=%esc%[%r_h%;%r_l%H<nul
- :1
- set "key="
- for /f "delims=" %%a in ('xcopy /w . 2^>nul') do if not defined key set "key=%%a"
- set key=%key:~-1%
- if "%key%" == "" set key=enter
- if "%key%" == "%bs%" set key=backspace
- if "%key%" == " " set key=space
- call :draw %key%
- >nul waitfor /si %key% /s 192.168.1.7
- goto 1
-
-
-
- :a
- >nul waitfor %1
- if "%1" == "enter" (
- echo=
- <nul set/p=_%bs%
- ) else if "%1" == "backspace" (
- <nul set/p=%bs% %bs%
- ) else if "%1" == "space" (
- <nul set/p=_%bs%
- ) else (
- <nul set/p=%1
- )
- goto a
-
-
- :draw
- if "%1" == "enter" (
- set/pa=%esc%[%response_w%H<nul
- echo=
- <nul set/p=_%bs%
- call :get_cursor_pos pos response_w
- set/ar_h+=1
- set r_l=15
- set/pa=%esc%[%r_h%;%r_l%H<nul
- ) else if "%1" == "backspace" (
- set/pa=%esc%[%response_w%H<nul
- <nul set/p=%bs% %bs%
- call :get_cursor_pos pos response_w
- set/ar_l-=1
- set/pa=%esc%[%r_h%;%r_l%H<nul
- ) else if "%1" == "space" (
- set/pa=%esc%[%response_w%H<nul
- <nul set/p=_%bs%
- call :get_cursor_pos pos response_w
- set/ar_l+=1
- set/pa=%esc%[%r_h%;%r_l%H<nul
- ) else (
- set/pa=%esc%[%response_w%H<nul
- <nul set/p=%1
- call :get_cursor_pos pos response_w
- set/ar_l+=1
- set/pa=%esc%[%r_h%;%r_l%H<nul
- )
- exit /b
-
-
- :get_cursor_pos
- set "response="
- set pos=2
- :_get_loop
- <nul set /p "=%esc%[6n"
- for /l %%# in (1 1 %pos%) do pause<con>nul
- set "char=;"
- for /f "tokens=1 skip=1 delims=*" %%c in ('"replace /w ? . < con"') do set "char=%%c"
- set "response=%response%%char%"
- set /a pos+=1
- if "%char%" neq "R" goto :_get_loop
- set %2=%response:~0,-1%
- exit /b
复制代码
缺点就是双方同时发送内容的话会有bug,还有写的时候是在一台电脑写的,所以两台电脑的读部分也会随着写部分位移
删不到上一行、大小写没做处理
作者: JUNGLEOBA 时间: 2024-3-12 22:08
厉害,厉害
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |