mk.exe,只有1,248字节
同时等待接受键盘和鼠标的输入,
win10和win XP 测试过可以使用。
支持全键盘按键,包括,控制键和状态键
支持鼠标左、右、中按键
支持定时、延时,程序节奏控制
增强版:3.5KB,最新请看11楼
使用方法,请从测试例子中找。
批处理使用测试例子- @echo off&setlocal enabledelayedexpansion
-
- if not exist mk.exe (
- (
- for /f "tokens=*" %%a in ('type "%~dpf0"') do (
- if "%%a" equ "-----BEGIN CERTIFICATE-----" set a=开始
- if defined a echo;%%a
- )
- )>mk.exe
- Certutil -Decode -f "mk.exe" "mk.exe" > nul
- )
-
- :loop
- for /f "tokens=1-5" %%1 in ('mk.exe') do (
- rem echo;%%1 %%2 %%3 %%4 %%5
-
- IF "%%1" equ "2" (
- set str=鼠标
- if "%%5" equ "1" (set str=移动!str!)
- if "%%5" equ "0" (
- if "%%4" equ "0" (set str=松开!str!)
- if "%%4" equ "1" (set str=按下!str!左键)
- if "%%4" equ "2" (set str=按下!str!右键)
- if "%%4" equ "4" (set str=按下!str!中键)
- )
- if "%%5" equ "4" if %%4 gtr 0 (set str=向上滚动!str!) else (set str=向下滚动!str!)
- set str=!str!,坐标:%%3行,%%2列
-
- ) else (
- set str=键盘
- if "%%4" equ "1" (set str=按下!str!) else (set str=松开!str!)
- if "%%2" equ "0" (set str=!str!扫描码是:%%3,状态码是:%%5) else (set str=!str!ASCII码是:%%2,状态码是:%%5)
- )
- )
-
- echo;!str!
- goto :loop
-
-
- pause
- goto :eof
- -----BEGIN CERTIFICATE-----
- TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
- AAAAAAAAAAAAAAAAwAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5v
- dCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABfVwu/GzZl7Bs2ZewbNmXs
- lSl27BY2ZeznFnfsGjZl7FJpY2gbNmXsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
- UEUAAEwBAgA4dJxhAAAAAAAAAADgAA8BCwEFDLABAAAgAQAAAAAAABACAAAQAgAA
- wAMAAAAAQAAQAAAAEAAAAAQAAAAAAAAABAAAAAAAAADgBAAAEAIAAAAAAAADAAAA
- AAAQAAAQAAAAABAAABAAAAAAAAAQAAAAAAAAAAAAAADoAwAAPAAAAAAAAAAAAAAA
- AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
- AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAMAACgAAAAAAAAAAAAAAAAAAAAAAAAA
- AAAAAAAAAAAudGV4dAAAAKoBAAAQAgAAsAEAABACAAAAAAAAAAAAAAAAAAAgAABg
- LnJkYXRhAAAcAQAAwAMAACABAADAAwAAAAAAAAAAAAAAAAAAQAAAQAAAAAAAAAAA
- 6BcAAABQ6G8BAAAlZCAlZCAlZCAlZCAlZA0KAFWL7IHESP///2Bq9uhZAQAAiYVg
- ////avXoTAEAAImFXP///42FZP///1D/tWD////oLgEAALif////I4Vk////g8gQ
- UP+1YP///+gmAQAAjYVo////UGoBjYVs////UP+1YP///+gFAQAAM8Bmi4Vs////
- UI+FWP///4P4AXU4ZouFev///1CPhVT///9mi4V2////UI+FUP////+1cP///4+F
- TP////+1fP///4+FSP///+tJ6zuD+AJ1NmaLhXD///9Qj4VU////ZouFcv///1CP
- hVD/////tXT///+PhUz/////tXz///+PhUj////rDGoC6IIAAADpUf////+1ZP//
- //+1YP///+hmAAAA/7VI/////7VM/////7VQ/////7VU/////7VY////aBsCQACN
- RYBQ6EwAAACDxBxQW2oAjYVo////UFONRYBQ/7Vc////6CgAAABhycPM/yXAA0AA
- /yXEA0AA/yXIA0AA/yXMA0AA/yXQA0AA/yXUA0AA/yXYA0AA/yXgA0AAAAAAAAAA
- TAQAAFoEAABsBAAAfAQAAJAEAACiBAAAqgQAAAAAAADEBAAAAAAAACQEAAAAAAAA
- AAAAALYEAADAAwAARAQAAAAAAAAAAAAA0AQAAOADAAAAAAAAAAAAAAAAAAAAAAAA
- AAAAAEwEAABaBAAAbAQAAHwEAACQBAAAogQAAKoEAAAAAAAAxAQAAAAAAACbAEV4
- aXRQcm9jZXNzAPIAR2V0Q29uc29sZU1vZGUAAGoBR2V0U3RkSGFuZGxlAAA0AlJl
- YWRDb25zb2xlSW5wdXRBAG4CU2V0Q29uc29sZU1vZGUAALcCU2xlZXAA9wJXcml0
- ZUZpbGUAa2VybmVsMzIuZGxsAAB9AndzcHJpbnRmQQB1c2VyMzIuZGxsAAAAAAAA
- -----END CERTIFICATE-----
复制代码 测试结果如下:- 鼠标,坐标:16行,54列
- 鼠标,坐标:16行,54列
- 鼠标,坐标:16行,54列
- 移动鼠标,坐标:16行,54列
- 移动鼠标,坐标:16行,55列
- 移动鼠标,坐标:16行,55列
- 鼠标,坐标:16行,55列
- 移动鼠标,坐标:16行,55列
- 移动鼠标,坐标:16行,55列
- 鼠标,坐标:16行,55列
- 按下键盘扫描码是:17,状态码是:8
- 松开键盘扫描码是:17,状态码是:0
- 移动鼠标,坐标:16行,55列
- 按下键盘ASCII码是:97,状态码是:0
- 松开键盘扫描码是:16,状态码是:0
- 按下键盘ASCII码是:102,状态码是:0
- 松开键盘ASCII码是:102,状态码是:0
- 按下键盘ASCII码是:100,状态码是:0
- 松开键盘ASCII码是:100,状态码是:0
- 按下鼠标左键,坐标:16行,55列
- 松开鼠标,坐标:16行,55列
- 鼠标,坐标:16行,55列
- 松开鼠标,坐标:16行,55列
- 移动鼠标,坐标:16行,55列
复制代码 MASM32,源码- comment * ?
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; Sample code for < Win32ASM Programming 2nd Edition>
- ; by netBenton,37659560
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; 编译链接:
- ;ml /c /coff mk.asm
- ;Link /SUBSYSTEM:CONSOLE /ALIGN:16 mk.obj
- ; 功能:
- ; mk.asm ---> CMD控制台最小的鼠标与键盘三方。
-
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
- ?*
-
- .586 ; create 32 bit code
- .model flat, stdcall ; 32 bit memory model
- option casemap :none ; case sensitive
-
- ;包含windows 关键字以及数据结构
- include \masm32\include\windows.inc
-
- ;包含API库
- include \masm32\include\kernel32.inc
- include \masm32\include\user32.inc
- include \masm32\include\masm32.inc
- ; 包含宏库
- include \masm32\macros\macro$.asm ;注意并非使用源版,是函数增加版。所有子过程作为函数使用在过程名后加 “$”
- ; include \masm32\macros\macros.asm
-
-
- includelib \masm32\lib\kernel32.lib
- includelib \masm32\lib\user32.lib
- includelib \masm32\lib\masm32.lib
-
- szText MACRO Name, Text:VARARG
- LOCAL lbl
- Name db Text,0dh,0ah,0
- ENDM
-
-
- STATE STRUCT
- dw ?
- dw ?
- STATE ENDS
-
- USBUFF STRUCT
- dw 64 dup (?)
- USBUFF ENDS
-
-
-
- .code
-
-
- ;程序入口
- start:
- call main
- invoke ExitProcess,eax
-
- ;这里定义数据,
- szText szTx,"%d %d %d %d %d"
- ;这里写代码
- main proc
- local @rvstring:USBUFF ;输入缓存
- local @inRec:INPUT_RECORD ;输入缓存结构定义
- local @state:STATE ;用来接收api调用返回值
- local @oldmode:DWORD ;原控制台模式,以备退出时恢复
- local @hStdIn:DWORD
- local @hStdOut:DWORD
- local @varar1:DWORD ;数据一
- local @varar2:DWORD ;...
- local @varar3:DWORD ;...
- local @varar4:DWORD ;...
- local @varar5:DWORD ;数据五
- pusha
-
- mov @hStdIn,fn$(GetStdHandle,STD_INPUT_HANDLE) ;获取输入句柄
- mov @hStdOut,fn$(GetStdHandle,STD_OUTPUT_HANDLE) ;获取输出句柄
- fn GetConsoleMode,@hStdIn,addr @oldmode ;获取输入模式
- mov eax,not (ENABLE_QUICK_EDIT_MODE or ENABLE_INSERT_MODE) ;清除快速编辑、插入模式
- and eax,@oldmode
- or eax,ENABLE_MOUSE_INPUT ;增加鼠标支持模式
- fn SetConsoleMode,@hStdIn,eax ;起用鼠标支持
-
- @@:
-
- fn ReadConsoleInputA,@hStdIn,addr @inRec,1,addr @state ;读取输入缓存
- xor eax,eax
- mov ax,@inRec.EventType ;处理字宽数据,清零高位。
- m2m @varar1,eax
-
- .if (eax == KEY_EVENT ) ;键盘事件
- mov ax,@inRec.KeyEvent.UnicodeChar ;转换后的 ASCII 字符
- m2m @varar2,eax
-
- mov ax,@inRec.KeyEvent.wVirtualKeyCode ;给定键的 虚拟键代码
- m2m @varar3,eax
- m2m @varar4,@inRec.KeyEvent.bKeyDown ;如果按下该键,则此成员为 TRUE。 否则,此成员为 FALSE
- m2m @varar5,@inRec.KeyEvent.dwControlKeyState ;控制键的状态。
-
- jmp @F
-
- .elseif (eax == MOUSE_EVENT ) ;鼠标事件
- mov ax,@inRec.MouseEvent.dwMousePosition.x ;列
- m2m @varar2,eax
- mov ax,@inRec.MouseEvent.dwMousePosition.y ;行
- m2m @varar3,eax
- m2m @varar4,@inRec.MouseEvent.dwButtonState ;按键
- m2m @varar5,@inRec.MouseEvent.dwEventFlags ;键状态,双击等
-
- jmp @F
-
- .endif
- fn Sleep,2 ;延迟等待事件处理完成
- jmp @B
- @@:
-
- fn SetConsoleMode,@hStdIn,@oldmode ;恢复原来输入模式
- invoke wsprintfA,addr @rvstring,offset szTx,@varar1,@varar2,@varar3,@varar4,@varar5 ;转换输出格式
-
- m2m ebx,eax ;用EAX传送参数回出错
- fn WriteFile,@hStdOut,addr @rvstring,ebx,addr @state,NULL ;输出结果,写标准句柄,输出到屏幕
- popa
-
- ret
-
- main endp
-
-
- end start
复制代码
|