News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Simulate Key Press & Freeze It

Started by xbtc, March 25, 2005, 08:29:52 AM

Previous topic - Next topic

xbtc

hi, i am extremely new 2 masm but am very willing to learn. What i am trying to do is have a program made (i got that far) and have it simulate key presses and freeze it in a timer, then when a hotkey is pressed kill the timer. Here is the code i have to simulate key presses:
invoke keybd_event,VK_S,0,0,0
invoke keybd_event,VK_S,0,KEYEVENTF_KEYUP,0

The buttons that i need are : Print Screen, and Left mouse button (button1 i guess)
now after that i was wondering is it possible to have multiple timers? i have 1 timer that checks for hot keys and when a key is press it inserts S like it sho uld. So would it be possible to add another timer? and if so how? and if so is it possible to say have Q be on so when Q is pressed : timer2.enabled = true and W can be off so  : when W is pressed timer2.enabled = false. I dont know how to add timers or anything , i know a little bit of visual basic but the visual basic progrma i could add the timer and all. any helpl is greatly  appreciated  :green

sluggy

xbtc,
there is a huge jump from VB to asm, they work in totally different ways, in asm you have to create everything yourself.

You can have as many timers as you want, use the API function SetTimer. As for the "hot keys" which aren't actually hot keys, you detect those in your WNDPROC event loop.

Vortex

Hi xbtc,

Welcome to the forum.

You can support your Visual Basic applications with DLLs coded in MASM  :U

xbtc

#3
invoke GetAsyncKeyState,VK_P
.if eax!=0
invoke keybd_event,VK_S,0,0,0
invoke keybd_event,VK_S,0,KEYEVENTF_KEYUP,0
.endif

^^ there is hte code to check to see if key P is pressed, and if it is true then it types S in.
so how would i go about freezeing it? would it be like

IsOn01 db 0
TIMER_ID01 equ 701;all this is defined up top?

invoke GetAsyncKeyState,VK_P
.if eax!=0
invoke SetTimer,hWin,2,90,NULL
Mov IsOn01,1
.endif
invoke GetAsyncKeyState,VK_O
.if eax!=0
Mov IsOn01,0
.endif

cmp IsOn01,1
je @F
@@:
invoke keybd_event,VK_S,0,0,0
invoke keybd_event,VK_S,0,KEYEVENTF_KEYUP,0
cmp IsOn01,0
je @F
invoke KillTimer,hWnd,TIMER_ID01
@@:

would this be right? i understand most of that but the part at cmp of it, it gets me confused there. keep in mind i just read a code som1 made on this so i tried 2 write my own to work like it should, so im sure there is some erors, or id idnt understand it right some where or something. does any know know the code for the keys Print Screen and Left Mouse Button? i tried VK_PRINTSCREEN and VK_MOUSE1 but they dont work.
PS: how do i keep the cmd window to stay open when i compile something so i can see the errors on it ? right now the cmd window closes w ehn its done compiling so it is terribly hard for me to view any errors. i have to use print screen adn then paste it in Paint, which can take me up to 5-10 minutes for me to press print screen at the right time to capture it, it is quite annoying  :'(

EDIT :
i finaly found a good list of key codes (that i needed)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/virtualkeycodes.asp
there is the link to them, if any one else needs it.
but i am still having the same problems as b4  :'(