Jump to content

Watch Tab Key Program Doesn't Quite Work...

- - - - -

  • Please log in to reply
1 reply to this topic

#1
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,251 posts
  • Location:C:\Countries\US
I am trying to make this program that is supposed to watch the tab key and output (to STDOUT) the state of the tab key (such as "Tab Key Down" or "Tab Key Up"), every time the tab key's state changes, but I also want the program to wait for the tab key to get back up before going on. I tried making this program using win32 assembly, but it, instead of switching from "Tab Key Down" to "Tab Key Up" and the other way every time the tab key's state changes, switches from "Tab Key Down" to "Tab Key Up", and the other way around, every time the tab key is pressed. Anyone know what's wrong?

.386 

.model flat, stdcall 

option casemap:none 

include \RS\include\ifiles.inc 

.data 

tabState                 dd 0 

.data? 

.code 

start: 


call watch_keys 


invoke ExitProcess, eax 


watch_keys proc 

	enter 0, 0 

	

	lp01: 

		invoke GetKeyState, 9 

		cmp eax, 0 

		jnz key_tab 

		invoke StdOut, string(13, "Tab Key Up  ") 

	jmp lp01 

	

	key_tab: 

		invoke StdOut, string(13, "Tab Key Down ") 

		

		tab_wait1: 

		invoke GetKeyState, 9 

		cmp eax, 0 

		jnz tab_wait1 

	jmp lp01 

	

	finish: 

	

	leave 

	ret 

watch_keys endp 


end start 


#2
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,251 posts
  • Location:C:\Countries\US
Okay. I think I got it.

This works:
.386 
.model flat, stdcall 
option casemap:none 
include \RS\include\ifiles.inc 
.data 
tabState                 dd 0 
.data? 
.code 
start: 

call watch_keys 

invoke ExitProcess, eax 

watch_keys proc 
	enter 0, 0 
	
	lp01: 
		invoke GetKeyState, 9 
		and eax, -2 
		cmp eax, 0 
		jnz key_tab 
		invoke StdOut, string(13, "Tab Key Up  ") 
	jmp lp01 
	
	key_tab: 
		invoke StdOut, string(13, "Tab Key Down ") 
		
		tab_wait1: 
		invoke GetKeyState, 9 
		and eax, -2 
		cmp eax, 0 
		jnz tab_wait1 
	jmp lp01 
	
	finish: 
	
	leave 
	ret 
watch_keys endp 

end start 





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users