problems with BLOCKINPUT and ONEVENT

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
pantik
Junior Coder
Posts: 45
Joined: Sun Dec 13, 2009 5:52 pm

problems with BLOCKINPUT and ONEVENT

Post by pantik » Sun Dec 13, 2009 6:12 pm

Hi all, i am spanish so please excuse me for my english.

This code works fine when i dont use "blockinput" but when i use it, the script hang up and it seems it is in a loop and i cannot exit. It appears as if the keys was pressed continuosly.

How can i do to use "blockinput" and that it works fine with "onevent". The same code without onevent works fine. Please help, i have already tried all what is my hand.

The code is to online poker soft. Thank you.

Code: Select all


    Let>tclick=0.05

//Dimesiones base de la ventana
    Let>defX=808
    Let>defY=627
//Boton All-in
    Let>pos9x=740
    Let>pos9y=510
//Boton Bajar apuesta (-)
    Let>pos10x=560
    Let>pos10y=529
//Punto vacio
    Let>pos11x=660
    Let>pos11y=470
//Boton derecho
    Let>pos12x=704
    Let>pos12y=560

OnEvent>KEY_DOWN,a,3,allin

Label>loop
Wait>0.01
goto>loop

SRT>allin
    //blocking>1  ---HERE IS THE PROBLEM---
    GetCursorPos>iniX,iniY
    GetActiveWindow>handle,,,sizeX,sizeY
    Let>pro9x={round(%pos9x%*(%sizeX%/%defX%))}
    Let>pro9y={round(%pos9y%*(%sizeY%/%defY%))}
    Let>pro10x={round(%pos10x%*(%sizeX%/%defX%))}
    Let>pro10y={round(%pos10y%*(%sizeY%/%defY%))}
    Let>pro12x={round(%pos12x%*(%sizeX%/%defX%))}
    Let>pro12y={round(%pos12y%*(%sizeY%/%defY%))}
    gosub>click,pro9x,pro9y,tclick
    gosub>click,pro10x,pro10y,tclick
    gosub>click,pro12x,pro12y,tclick
    MouseMove>iniX,iniY
    blockinput>0
END>allin

SRT>click
    MouseMoveRel>click_var_1,click_var_2
    WaitCursorChanged>0.05
    LDown
    Wait>click_var_3
    LUp
    Wait>click_var_3
END>click

PD: I use Windows XP SP2.

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sun Dec 13, 2009 6:36 pm

Well ...

- BlockInput prevents keyboard input.
- OnEvent KEY_DOWN requires keyboard input.

You can't really stop the user using the keyboard and then hope to respond to the user using the keyboard. :-/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

pantik
Junior Coder
Posts: 45
Joined: Sun Dec 13, 2009 5:52 pm

Post by pantik » Sun Dec 13, 2009 6:56 pm

I know it, but "blockinput" is used inside a subrutine that is called from OnEvent. Have you see my code ? I use blockinput>0 before exit of the subrutine. In a abbreviate form it would be so:

Onvent>KEY_DOWN,a,3,xxx

Label>loop
Wait>0.01
goto>loop

srt>xxx
blockinput>1
....
....
blockinput>0
end>xxx

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Dec 14, 2009 10:59 am

You actually have "blocking>1". Not BlockInput>1
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

pantik
Junior Coder
Posts: 45
Joined: Sun Dec 13, 2009 5:52 pm

Post by pantik » Mon Dec 14, 2009 2:02 pm

It only is a typo. I have it written well in my script.

The problem is that when Blockinput is activated the keys are still pressed therefore it stays in a loop.
I can solucionate the problem including Wait>2 in the first line of the subroutine:

Onevent>KEY_DOWN,a,3,xxx
label>loop
Wait>0.01
goto>loop

srt>xxx
Wait>2
Blockinput>1
....
....
Blockinput>0
end>xxx

but its too slow to my purpose.
If i include Release ALT in the first line of the subroutine only "a" key stays pressed since the script go out of the subroutine but onevent call to the subroutine only pressing ALT. i tried "Release a" but does not work.

Any other solution?

Thanks.

User avatar
JRL
Automation Wizard
Posts: 3518
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Dec 14, 2009 2:32 pm

This is untested in your script but perhaps what I call an event flag will help. I set a variable as a flag and allow or not allow events based on the value of the flag. I've written a flag variable into your originally posted code. This should prevent the onevent keypress from occurring more than once if the key is held down. The delay between one key press and another is determined by the delay variable.

hope this makes sense and is helpful.

Code: Select all

    Let>tclick=0.05
    Let>KeyPressFlag=0
    Let>Delay=10

//Dimesiones base de la ventana
    Let>defX=808
    Let>defY=627
//Boton All-in
    Let>pos9x=740
    Let>pos9y=510
//Boton Bajar apuesta (-)
    Let>pos10x=560
    Let>pos10y=529
//Punto vacio
    Let>pos11x=660
    Let>pos11y=470
//Boton derecho
    Let>pos12x=704
    Let>pos12y=560

OnEvent>KEY_DOWN,a,3,allin

Label>loop
  If>KeyPressFlag>0
    Add>KeyPressFlag,1
    If>KeyPressFlag>%Delay%
      Let>KeyPressFlag=0
    EndIf
  EndIf
  Wait>0.01
goto>loop

SRT>allin
    If>KeyPressFlag<1
      Let>KeyPressFlag=1
      blockinput>1
      GetCursorPos>iniX,iniY
      GetActiveWindow>handle,,,sizeX,sizeY
      Let>pro9x={round(%pos9x%*(%sizeX%/%defX%))}
      Let>pro9y={round(%pos9y%*(%sizeY%/%defY%))}
      Let>pro10x={round(%pos10x%*(%sizeX%/%defX%))}
      Let>pro10y={round(%pos10y%*(%sizeY%/%defY%))}
      Let>pro12x={round(%pos12x%*(%sizeX%/%defX%))}
      Let>pro12y={round(%pos12y%*(%sizeY%/%defY%))}
      gosub>click,pro9x,pro9y,tclick
      gosub>click,pro10x,pro10y,tclick
      gosub>click,pro12x,pro12y,tclick
      MouseMove>iniX,iniY
      blockinput>0
    EndIf
END>allin

SRT>click
    MouseMoveRel>click_var_1,click_var_2
    WaitCursorChanged>0.05
    LDown
    Wait>click_var_3
    LUp
    Wait>click_var_3
END>click

pantik
Junior Coder
Posts: 45
Joined: Sun Dec 13, 2009 5:52 pm

Post by pantik » Mon Dec 14, 2009 3:36 pm

Thanks for your reply. I have tested your code but does not work. The subroutine (allin) called by onevent is executed in a loop with a delay determined by the delay variable. IMO "blockinput>1" does not allow the key is released.

Is not there any function which forces the key releases? Some as "RELEASE ALT". ( I tried RELEASE a but does not work) It would exist somothing as "RELEASE a" it would be my solution.

I have been reading another post and i have seen the use of "keybd_event" and searching info and i have found in user32.dll the function getkeystate. Buti i have never used function of libreries.
Any suggestion of how can i use this function.

User avatar
JRL
Automation Wizard
Posts: 3518
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Dec 14, 2009 3:43 pm

What is the purpose for using BlockInput>? If it was an attempt to disable the key press try removing the BlockInput and only use the keypressflag variable.

pantik
Junior Coder
Posts: 45
Joined: Sun Dec 13, 2009 5:52 pm

Post by pantik » Mon Dec 14, 2009 4:37 pm

JRL wrote:What is the purpose for using BlockInput>? If it was an attempt to disable the key press try removing the BlockInput and only use the keypressflag variable.
The purpose is prevent mouse move and there is not error in the clicks positions. Without blockinput the script works fine and i dont need keypressflag.

pantik
Junior Coder
Posts: 45
Joined: Sun Dec 13, 2009 5:52 pm

Post by pantik » Mon Dec 14, 2009 7:59 pm

I found the solution!!

Code: Select all

Onevent,KEY_DOWN,a,3,xxx

label>loop
Wait>0.01
goto>loop

srt>xxx
   Let>flags={1 OR 2}
   LibFunc>user32.dll,keybd_event,r,65,0,flags,0
   Release ALT
   blockinput>1
   ....
   ....
   blockinput>0
end>xxx

Really was it as dificult to you ? :lol:
Thanks everybody anyway.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts