Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

force current position on move_mouse() to solve windows bug #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

carrot69
Copy link
Owner

@carrot69 carrot69 commented Apr 5, 2024

No description provided.

@m-jonas
Copy link

m-jonas commented Apr 9, 2024

Hi @carrot69

Thanks for looking into this. Just ran the code in this new branch but got the same error:

line 124, in move_mouse
    new_x = currentPosition[0] + delta_x
TypeError: 'NoneType' object is not subscriptable

Jonas

@carrot69
Copy link
Owner Author

carrot69 commented Apr 9, 2024

Hey @m-jonas!

Sorry, I made a mistake with the variable name. I guess I'll need to refactor since I have two variables that are called the same but one with an underscore and the other with snake case.

Can you verify now?

Thanks!

@m-jonas
Copy link

m-jonas commented Apr 9, 2024

Hey @carrot69

I'm afraid the error still the same.

Jonas

@m-jonas
Copy link

m-jonas commented Apr 9, 2024

I have done some troubleshooting, where I have added a few print statements:

image

This is the outcome:

image

Observe that the currentPosition tuple is deleted (?) as an object upon Windows lock.

More observations: I have tested and I believe it is pressing CTRL+ALT+DEL that kills the script somehow, and not the Windows lock action. I have tested it by pressing CTRL+ALT+DEL and then pressing ESC to go back, instead of selecting 'Lock'. I can then see the script has already failed.

@carrot69
Copy link
Owner Author

carrot69 commented Apr 9, 2024

Based on what you say and on this link: moses-palmer/pynput#81

My best guess is that pynput returns the mouse position as None because the screen is locked.

I'm going to install Windows on a virtual machine so I can check this out and look for an elegant solution, but in the meanwhile you can try something like:

    currentPosition = mouse.position

    if currentPosition == None:
        currentPosition = (0,0)

    new_x = currentPosition[0] + delta_x
    ...

Does this work?

@m-jonas
Copy link

m-jonas commented Apr 9, 2024

It worked!

image

Nice and simple solution :)

@carrot69
Copy link
Owner Author

carrot69 commented Apr 9, 2024

Yeah :D

I'm glad it worked!

I'm going to do a little refactoring and improve this pull request so I can push the fix to master.

Thanks for reporting this and helping debug it :)

@m-jonas
Copy link

m-jonas commented Apr 9, 2024

No problem, glad to help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: 'NoneType' object is not subscriptable
2 participants