The MASM Forum

General => The Campus => Topic started by: Magnum on January 03, 2013, 03:37:26 PM

Title: Stop on key press or mouse input
Post by: Magnum on January 03, 2013, 03:37:26 PM
I would to make this program stop if it detects any key press or mouse input.

Vielen Dank.



;Telephone.asm
;              Simulate telephone ringing
;              Help from SuperDave -- a.k.a. DednDave,             PRODUCE 1 KHz TONE FOR 54.9 mS
;              PRODUCE 800 Hz TONE FOR 54.9 mS

.486                       ; create 32 bit code
.model flat, stdcall       ; 32 bit memory model
option casemap :none       ; case sensitive

include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\shell32.inc
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\shell32.lib
include \masm32\macros\macros.asm

.data

.code 
                 
start:

mov ecx, 20
@@:
push ecx
invoke Beep, 1000, 55 ; Frequency in hertz and sound duration
invoke Beep, 800, 55   
pop ecx
dec ecx
jnz @B
invoke Sleep, 1500   

mov ecx, 20
@@:
push ecx
invoke Beep, 1000, 55 ; Frequency in hertz and sound duration
invoke Beep, 800, 55   
pop ecx
dec ecx
jnz @B
invoke Sleep, 1500

mov ecx, 20
@@:
push ecx
invoke Beep, 1000, 55 ;
invoke Beep, 800, 55   
pop ecx
dec ecx
jnz @B

invoke ExitProcess,0

end start


Title: Re: Stop on key press or mouse input
Post by: hutch-- on January 03, 2013, 04:07:49 PM
Andy,

Just set a variable as a flag.


.data?
  flag dd ?
-------
.code
  mov flag, 0  ; initialise to zero


Trap either or both mouse or keyboard messages then set the flag to non-zero. You can also set some other keystroke to start it again.