问题描述
所以现在我只能让它循环并等待点击,但是,一旦我点击,程序认为我仍然在按住点击或其他东西,因为一旦我点击按钮状态就永远不会改变.所以程序只是循环到无穷大。
这是我所拥有的:
.286
TITLE ''
.MODEL SMALL
.STACK
.DATA
clickR DB 'Right click',10,13,'$'
; clickI DB 'Left click','$'
.CODE
main PROC FAR
MOV AX,@DATA
MOV DS,AX
MOV AX,0h ; Init mouse
INT 33h
MOV AX,01h ; Show pointer
INT 33h
mouse:
MOV AX,05h ; Query Button-pressed Counter
MOV BX,00h ; Left button
INT 33h
CMP AX,01h ; Check left button status
JNE mouse ; Not pressed? Go back
CMP BX,02h ; Check if it has been pressed twice
JB right ; < 2? Go to label
JAE quit ; >= 2? quit
JMP mouse
right:
MOV AH,09h ; Print that r-click has been pressed
LEA DX,clickR
INT 21h
JMP mouse ; Go back to mouse loop
quit:
MOV AX,4C00h
INT 21h
main ENDP
END main
解决方法
使用 AH=3 RETURN POSITION AND BUTTON STATUS 而不是 AH=5
。
当它返回BX=1
(左按钮按下)时,重复查询并等待BX=0
(按钮向上)。
如果您需要检测双击,请再次重复这两个查询。
,基于 vitsoft 所说的解决方案
现在,这是我修复它的方式(它可能不是最佳的,但它有效):
.286
TITLE ''
.MODEL SMALL
.STACK
.DATA
clickR DB 'Right click',10,13,'$'
released DB 'Released','$'
.CODE
rightC PROC NEAR
MOV AH,09h
LEA DX,clickR
INT 21h
RET
rightC ENDP
releaseStr PROC NEAR
MOV AH,released
INT 21h
RET
releaseStr ENDP
main PROC FAR
MOV AX,@DATA
MOV DS,AX
MOV AX,0h ; Init mouse
INT 33h
MOV AX,01h ; Show pointer
INT 33h
XOR CX,CX ; Init counter
PUSH CX ; Save counter
mouse:
MOV AX,03h ; Query Position / Button Status
INT 33h
CMP BX,01h ; Check left button status
JNE mouse ; Not pressed? Go back
CALL rightC ; Print that r-click has been pressed
release:
MOV AX,03h ; Query Position / Button Status
INT 33h
CMP BX,00h ; Check button status (None)
JNE release ; Still no released? Go back
CALL releaseStr ; Print that r-click has been released
POP CX ; Return counter
INC CX ; Counter + 1 = r-click has been pressed and released one time
CMP CX,02h ; Check if this has happened twice
JAE quit ; Yes? quit
PUSH CX ; No? Save counter
JMP mouse ; Go back to mouse loop
quit:
MOV AX,4C00h
INT 21h
main ENDP
END main
,
CMP AX,01h ; Check left button status
JNE mouse ; Not pressed? Go back
如果您想等待 2 次点击,您还必须允许释放按钮!上面的代码使这变得不可能,因为您坚持让按钮处于按下状态。
接下来的代码等待鼠标左键点击 2 次并退出:
MOV AX,0000h ; Init mouse
INT 33h
MOV AX,0001h ; Show pointer
INT 33h
mouse:
MOV AX,0005h ; Query Button-Pressed Counter
XOR BX,BX ; Left button
INT 33h
CMP BX,2 ; Check if it has been pressed twice
JB mouse ; < 2? Go to label
quit:
MOV AX,4C00h
INT 21h