String Masm32通过按键终止程序
我已经做了一些研究,但仍然找不到关于如何通过按和F1-F12键从终端终止汇编程序的有效答案 我有这样一个简单的程序:String Masm32通过按键终止程序,string,input,terminate,masm32,String,Input,Terminate,Masm32,我已经做了一些研究,但仍然找不到关于如何通过按和F1-F12键从终端终止汇编程序的有效答案 我有这样一个简单的程序: .data prompt1 BYTE "Please Input a sentence.",0Dh,0Ah,0 .code Main Proc mov edx,OFFSET prompt1 call WriteString call ReadString exit main ENDP main END 我听说过这个INT16h来检查是否按下了一个键,但是在最简单的例子中是
.data
prompt1 BYTE "Please Input a sentence.",0Dh,0Ah,0
.code
Main Proc
mov edx,OFFSET prompt1
call WriteString
call ReadString
exit
main ENDP
main END
我听说过这个INT16h来检查是否按下了一个键,但是在最简单的例子中是如何实现的?提前感谢您的帮助。在MASM论坛()中为您找到了一个很好的例子。代码不是我的,但我以前写过这样的代码
.XCREF
.NOLIST
INCLUDE \masm32\include\masm32rt.inc
.LIST
;#########################################################################
.CODE
;*************************************************************************
_main PROC
print chr$('Press Esc to Exit'),13,10
jmp short kloop2
kloop1: INVOKE Sleep,40
kloop2: call InKyb
jz kloop1
push eax
cmp ah,0
jz kloop3
push 2020h
jmp short kloop4
kloop3: mov ah,20h
push eax
kloop4: print esp
pop edx
pop eax
push eax
print right$(uhex$(eax),4),13,10
pop eax
cmp eax,1Bh
jnz kloop2
exit
_main ENDP
;*************************************************************************
InKyb PROC
;Polled Keyboard Input - DednDave 8, 2010
;
;This function returns a keystroke in EAX if there is one in the buffer.
;If the buffer is empty, the function returns immediately.
;
;If the keyboard buffer is empty, AH = 0, AL = 0, ZF = 1.
;If the stroke is a regular key, AH = 0, AL = key char, ZF = 0.
;If the stroke is an extended key, AH = extended key, AL = E0h, ZF = 0.
;If the stroke is a function key, AH = function key, AL = 0, ZF = 0.
;
;ECX, EDX are not preserved.
call crt__kbhit
or eax,eax
jz InKyb1
call crt__getch
and eax,0FFh
jz InKyb0
cmp al,0E0h
jnz InKyb1
InKyb0: push eax
call crt__getch
pop edx
shl eax,8
or eax,edx
InKyb1: retn
InKyb ENDP
;#########################################################################
END _main
看起来您正在使用Irvine32库。只需使用库中的
ReadKey
功能:
.data
prompt1 BYTE "Please Input a sentence.",0Dh,0Ah,0
.code
Main:
mov edx,OFFSET prompt1
call WriteString
call ReadString
push VK_F23
call WaitForKeyPress
exit
WaitForKeyPress proc VKey:byte
ReadIt:
mov eax, 10
call Delay
call ReadKey
jz ReadIt
cmp ah, VKey
jne ReadIt
ret
WaitForKeyPress endp
END Main
对于我的键盘,我需要通过VK_F23
以按F12键退出。您可以尝试将VK_F12
传递到WaitForKeyPress
并查看系统上发生了什么