Automatic mouse movement

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
akakyouryuu
Regular
Posts: 153
Joined: Fri Nov 30, 2012 10:29 am
Contact:

Automatic mouse movement

#1 Post by akakyouryuu » Fri Nov 30, 2012 11:03 am

When dialog is displayed, I want to move the mouse to the yes button of a dialog automatically.
Can ren'py do this?

User avatar
akakyouryuu
Regular
Posts: 153
Joined: Fri Nov 30, 2012 10:29 am
Contact:

Re: Automatic mouse movement

#2 Post by akakyouryuu » Fri Dec 07, 2012 4:33 am

I resolved this problem by oneself.
I write the below code.
I can't explain the particulars of this in English, but maybe you will understand it, if you read it.
---automouse.rpy

Code: Select all

#functions
#automouse_jump(x, y)
#jump to (x,y)
#automouse_move(x, y, time_ms)
#move to (x,y) in time_ms
#automouse_get_pos() return (x, y)
# get mouse coordinates

init python:
    import pygame

    def automouse_yesno_prompt(*args):
        automouse_move(250, 150, 100)
        return yesno_prompt_org(*args)

    def automouse_jump(x, y):
        x, y = automouse_windowmode_pos_to_true_pos(x, y)
        pygame.mouse.set_pos([x, y])

    def automouse_move(goalx, goaly, time_ms):
        goalx, goaly = automouse_windowmode_pos_to_true_pos(goalx, goaly)
        starttime = pygame.time.get_ticks()
        startx, starty = pygame.mouse.get_pos()
        speedx = ( float(goalx - startx) / float(time_ms) )
        speedy = ( float(goaly - starty) / float(time_ms) )
        while(1):
            nowtime = pygame.time.get_ticks()
            pygame.mouse.set_pos([speedx*(nowtime-starttime)+startx, speedy*(nowtime-starttime)+starty])
            if nowtime - starttime >= time_ms:
                break

    def automouse_get_pos():
        x, y = pygame.mouse.get_pos()
        return automouse_true_pos_to_windowmode_pos(x, y)

    def automouse_blackline_pos():
        videoinfo = pygame.display.Info()
        now_w = float(videoinfo.current_w)
        now_h = float(videoinfo.current_h)
        def_w = float(config.screen_width)
        def_h = float(config.screen_height)
        if now_w * (def_h / def_w) <= now_h:
            return (0, int(( now_h -  now_w * (def_h / def_w) ) / 2))
        else:
            return (int(( now_w -  now_h * (def_w / def_h) ) / 2), 0)

    def automouse_windowmode_pos_to_true_pos(x, y):
        videoinfo = pygame.display.Info()
        now_w = float(videoinfo.current_w)
        now_h = float(videoinfo.current_h)
        def_w = float(config.screen_width)
        def_h = float(config.screen_height)

        bl_x, bl_y = automouse_blackline_pos()
        bl_x = float(bl_x)
        bl_y = float(bl_y)
        X = x * (now_w - 2*bl_x) / def_w
        Y = y * (now_h - 2*bl_y) / def_h
        return (int(X + bl_x), int(Y + bl_y))

    def automouse_true_pos_to_windowmode_pos(x, y):
        videoinfo = pygame.display.Info()
        now_w = float(videoinfo.current_w)
        now_h = float(videoinfo.current_h)
        def_w = float(config.screen_width)
        def_h = float(config.screen_height)

        bl_x, bl_y = automouse_blackline_pos()
        bl_x = float(bl_x)
        bl_y = float(bl_y)

        X = (float(x) - bl_x) * def_w / (now_w - 2*bl_x)
        Y = (float(y) - bl_y) * def_h / (now_h - 2*bl_y)
        return (int(X), int(Y))

    yesno_prompt_org = layout.yesno_prompt
    layout.yesno_prompt = automouse_yesno_prompt


User avatar
kuri_chii
Regular
Posts: 69
Joined: Sat Apr 27, 2013 10:34 am
Completed: RHWIMY beta 1.0
Projects: Right here where I met you, Love Snatch, Monarchy High
Organization: VND - AWA
IRC Nick: Kuri
Deviantart: franzzzz002
Skype: franz.mole
Location: Somewhere in Asia
Contact:

Re: Automatic mouse movement

#3 Post by kuri_chii » Sat Jun 08, 2013 10:31 am

does this work at the latest renpy?
The best way showing your feelings is to write Novel Stories :3
Image
DeviantArt | Monarchy High | RHWIMY | Love Snatch

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Automatic mouse movement

#4 Post by nyaatrap » Sat Jun 08, 2013 1:19 pm

Yes. I'm using his script on my latest commercial game made with ren'py 6.15.5
Though he added screen actions:

Code: Select all

    class MouseMove(Action):
        def __init__(self, x, y, time):
            self.x = x
            self.y = y
            self.time = time
        def __call__(self):
            automouse_move(self.x, self.y, self.time)

    class MouseJump(Action):
        def __init__(self, x, y):
            self.x = x
            self.y = y
        def __call__(self):
            automouse_jump(self.x, self.y)
Use these actions instead of automouse_yesno_prompt(*args)

User avatar
kuri_chii
Regular
Posts: 69
Joined: Sat Apr 27, 2013 10:34 am
Completed: RHWIMY beta 1.0
Projects: Right here where I met you, Love Snatch, Monarchy High
Organization: VND - AWA
IRC Nick: Kuri
Deviantart: franzzzz002
Skype: franz.mole
Location: Somewhere in Asia
Contact:

Re: Automatic mouse movement

#5 Post by kuri_chii » Sat Jun 08, 2013 3:59 pm

nyaatrap wrote:Yes. I'm using his script on my latest commercial game made with ren'py 6.15.5
Though he added screen actions:

Code: Select all

    class MouseMove(Action):
        def __init__(self, x, y, time):
            self.x = x
            self.y = y
            self.time = time
        def __call__(self):
            automouse_move(self.x, self.y, self.time)

    class MouseJump(Action):
        def __init__(self, x, y):
            self.x = x
            self.y = y
        def __call__(self):
            automouse_jump(self.x, self.y)
Use these actions instead of automouse_yesno_prompt(*args)

where should I put his script and your action?
The best way showing your feelings is to write Novel Stories :3
Image
DeviantArt | Monarchy High | RHWIMY | Love Snatch

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Automatic mouse movement

#6 Post by nyaatrap » Sun Jun 09, 2013 2:34 am

Anywhere on your .rpy file, or make a new .rpy file and paste them.
To use this, write actions in the screens like this: http://lemmasoft.renai.us/forums/viewto ... 29#p276565

User avatar
XxrenxX
Veteran
Posts: 267
Joined: Tue Oct 02, 2012 2:40 am
Projects: Chasing
Deviantart: bara-ettie
Location: Canada
Contact:

Re: Automatic mouse movement

#7 Post by XxrenxX » Sat Dec 14, 2013 11:19 pm

I want to use something like this in my game but I don't understand this code or how to get it to work.

I found the automatic move in the screen actions, values and functions page.

Code: Select all

hotspot (351,260,32,21) action Preference("automatic move", "enable")
hotspot (383,260,38,18) action Preference("automatic move", "disable")
And it's something I want to implement in my game for the yes/no prompts. In short move the mouse to the center between the yes and no. Added the button so players could set this function to on and off but the code he created seems to be different so it wont work. Also 'automatic move' isn't a preference?

I'm just overall confused by this and I don't see a point in starting a new topic since this one already exists.

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]