Shake Mouse!

Share your advanced PureBasic knowledge/code with the community.
Peyman
Enthusiast
Enthusiast
Posts: 203
Joined: Mon Dec 24, 2007 4:15 pm
Location: Iran

Shake Mouse!

Post by Peyman »

Lets Fun :D :D

Code: Select all

Procedure ShakeMouse(shakiness.l)
    rect.POINT
    GetCursorPos_(rect)
       
        randX = Random(1)
        randY = Random(1)
        
        If randX = 0
            XX = rect\x - shakiness
        Else
            XX = rect\x + shakiness
        EndIf
        
        If randY = 0
            YY = rect\y - shakiness
        Else
            YY = rect\y + shakiness
        EndIf
        
        
        SetCursorPos_(XX, YY)
EndProcedure

For a=0 To 1000
  Delay(1)
  ShakeMouse(2)
Next
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

what's your PB version?

the SetCursorPos call is not correct that way.
oh... and have a nice day.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Hi,

Nice idea. Funny ^^
Just another try.

Code: Select all

Procedure ShakeMouse( nIntensity.i , tmTimeMS.i )
    Protected ptMouse.POINT
    Protected nX     .i
    Protected nY     .i
    Protected tmEndMS.i
    Protected nCount .i
    
    GetCursorPos_( ptMouse )
    
    tmEndMS = ElapsedMilliseconds () + tmTimeMS
    While tmEndMS > ElapsedMilliseconds ()
       nX = ptMouse\x + ( Sin ( nCount ) * Random ( nIntensity ) )
       nY = ptMouse\y + ( Cos ( nCount ) * Random ( nIntensity ) )
       SetCursorPos_( nX , nY )
       nCount = ( nCount + 1 ) % 360
       Delay ( 10 )
    Wend
       
   ProcedureReturn #Null
EndProcedure

 
ShakeMouse ( 15 , 500 )
 
Regards

Wolf
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Kaeru Gaman wrote:the SetCursorPos call is not correct that way.
Looks correct to me. What would you consider the correct way :?:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

did I mix momething up?

I thought, API calls awaiting a POINT meanwhile expect the full 64bit Struct as parameter, not two separated 32bit values.

just like WindowFromPoint etc.
oh... and have a nice day.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

SetCursorPos_ doesn't use a POINT structure, it uses two integers, x and y.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

ok, sorry....

the API is inconsistent there, but I could have looked it up.
oh... and have a nice day.
Andesdaf
User
User
Posts: 85
Joined: Sun Mar 22, 2009 2:53 pm
Location: GER, Saxony

Post by Andesdaf »

@Peyman & Wolf:

funny idea. :D It ist difficult to click on the "kill program" button with this
code :wink:
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

Andesdaf wrote:@Peyman & Wolf:

funny idea. :D It ist difficult to click on the "kill program" button with this
code :wink:
I tested the code with a drawing program. I started the MouseShake, then I switched to the drawing program and held down the mouse buttons to draw. It produced a rather nice scribble pattern. :wink:
Andesdaf
User
User
Posts: 85
Joined: Sun Mar 22, 2009 2:53 pm
Location: GER, Saxony

Post by Andesdaf »

Demivec wrote:
Andesdaf wrote:@Peyman & Wolf:

funny idea. :D It ist difficult to click on the "kill program" button with this
code :wink:
I tested the code with a drawing program. I started the MouseShake, then I switched to the drawing program and held down the mouse buttons to draw. It produced a rather nice scribble pattern. :wink:
Oh yes, that's funny :).

With Hroudtwolf's code, i can't move the mouse no longer and so it draws
a thing like a ball.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

Imagine a "nag" that did that to you while the software was unregistered ;)
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Post Reply