Mar-24-2020, 06:53 PM
Hi, so I've had this code that caused the mouse cursor to move in a specific pattern. I ran it via Windows Powershell via the following steps:
- running Powershell as admin
- pasting '[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Users\User\AppData\Local\Programs\Python\Python36")' (outside quotes not included of course)
- typing 'python'
- pasting the actual code
It worked effectively before, then all of a sudden, without uninstalling or changing anything, I get this error:
Anyone know the root cause of this and how to fix this? I apologize if it's an easy fix and this is a dumb question, I'm in the extreme shallow ends when it comes to the language. I have tried reinstalling mouse/keyboard packages, win32api, and even python itself. Again, it was working just fine for the longest time, then all of a sudden this error came up. Any help would be much appreciated, thanks! Code itself is just below:
- running Powershell as admin
- pasting '[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Users\User\AppData\Local\Programs\Python\Python36")' (outside quotes not included of course)
- typing 'python'
- pasting the actual code
It worked effectively before, then all of a sudden, without uninstalling or changing anything, I get this error:
1 2 3 |
Traceback (most recent call last): File "<stdin>" , line 2 , in <module> NameError: name 'win32api' is not defined |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
import win32api import mouse from time import sleep import random from random import randint # Digits runter = [ 18 , 18 , 14 , 14 , 14 , 14 , 14 , 14 , 14 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] cunter = [ - 4 , - 4 , - 4 , - 4 , - 4 , - 4 , - 4 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] # vars count = 0 EinAus = False jaornein = randint( 0 , 1 ) # Loop count = 0 while True : if win32api.GetAsyncKeyState( ord ( '0' )): EinAus = not EinAus sleep( 0.2 ) print ( 'On' ) sleep( 0.2 ) while EinAus is True : count = 0 while mouse.is_pressed(button = 'left' ): if count < 40 : jaornein = randint( 0 , 1 ) if jaornein = = 1 : randomized = randint( 0 , 5 ) elif jaornein = = 0 : randomized = random.uniform( 0 , - 5 ) print (randomized) ammount = runter[count] drew = cunter[count] if jaornein = = 1 : ammount = ammount + randomized drew = drew + randomized elif jaornein = = 0 : ammount = ammount - randomized drew = drew - randomized ammountFinal = int ( round (ammount)) drewFinal = int ( round (drew)) win32api.mouse_event( 0x0001 ,drewFinal,ammountFinal) sleep( 0.10 ) count = count + 1 if count > 40 : count = 0 ammount = 0 drew = 0 if win32api.GetAsyncKeyState( ord ( '0' )): print ( 'Out' ) EinAus = not EinAus sleep( 0.2 ) break sleep( 0.1 ) |