So I dont have code because its not an issue with coding as I already have the program done and working however I noticed that:
In gaming menus mouse sensitivity doesnt matter because I set coords to click/move and since its not sensitivity related it works just fine.
However,
When moving a game camera(character view) if I do for example 'move 1000 pixels to the right' this will be affected by mouse sensitivity & ingame sensitivity is there no way to make this work in all resolutions / mouse sensitivity?
Essentially I need to be able to make my friends 'camera"/'character view' to move as much as mine while having a different mouse DPI
Instead of moving in a relative way move to a fixed point of your display for example:
import pyautogui
import time
time.sleep(3)
pyautogui.moveTo(100, 100)
This will move your mouse to 100 pixels along 100 pixels down on your monitor. Other examples:
# To make it drag along the screen
# (x, y, time taken)
pyautogui.moveTo(100, 100, 5)
# To make it hold while moving
# The 5 slows it
pyautogui.dragTo(100, 100, 5)
# To check if the next move pos is on display
# This will return false
pyautogui.onScreen(0, -1)
# To Move only x/y
pyautogui.moveTo(None, 500)
Allthough pyautogui should only move directional to the pixels irrespective of the DPI so may you please attach your code.
Related
mousepos = mouse.get_position()
if mousecontrol: # mouse control can be toggled
CAMERAANGLE[0] -= (mousepos[1] - pastcoords[1])*SENS # camera x angle
CAMERAANGLE[1] -= (mousepos[0] - pastcoords[0])*SENS # camera y angle
mouse.move(960,540) # resetting mouse to center of screen
pastcoords = mouse.get_position() # resetting mouse for next frame to calculate the distance the mouse travelled in a frame
^ this code is in a while loop and runs once every time the loop runs
This code works fine for computers at my school, however when I run this code on my home PC, the mouse control is extremely jittery and doesn't work.
My school computers run windows 10 with an Intel i5 10500T, and my home computer runs windows 10 with a 12400f and an RTX 3060
I added a timer to slow down the framerate, however this didn't fix the problem. Does anyone know what's going on here?
It might be that the issue is with the mouse control implementation. The jitteriness might be caused by a difference in the processing power or mouse sensitivity between the two computers, or due to a difference in the mouse driver or hardware. It is also possible that there is a difference in the refresh rate or resolution between the two displays, which could be affecting the mouse position calculation. To solve this issue, you can try adjusting the mouse sensitivity, or try using a different mouse to see if the issue is with the hardware. You could also try running the code on a different display or resolution to see if that makes a difference.
The mouse would move a distance between mousepos = mouse.get_position() and pastcoords = mouse.get_position(), resulting in an inaccuracy in the mouse position - I fixed it by changing the code to this:
mousepos = mouse.get_position()
if mousecontrol: # mouse control can be toggled
CAMERAANGLE[0] -= (mousepos[1] - 540)*SENS # camera x angle
CAMERAANGLE[1] -= (mousepos[0] - 960)*SENS # camera y angle
mouse.move(960,540) # resetting mouse to center of screen
At the program start, you should disable all turtle animations and make the turtle hidden. Next your program should implement the following requirements.
Prompt the user for a couple of inputs, the grid size N and a difficulty level between 1 to 3.
Draw an N × N grid as shown in this figure. Put the game title, start button and score on the top.
Handle mouse clicks in the turtle window. Clicking on the start button should, well, start the game but other clicks should be ignored.
Implement the gameplay, which includes displaying ten squares on the grid one after the other. Display the current square number (1 to 10) at the top. Each square should occupy a random box on the grid. A square would only stay on screen for a period of 2, 1.5 or 1 seconds, corresponding to difficulty levels of 1, 2 and 3 respectively.
Let the user play the game with mouse. Objective of the game is to shoot (click) as many squares as possible. A hit increases the score and a miss deducts the score by one. Only the clicks inside grid boundaries should be entertained. If a square is successfully hit, its colour should change to give user an indication of success.
Once the time is elapsed for all ten squares, replace the box number at the top with the ‘finished’ label.
Note that turtle graphics do not provide support for erasing a part of drawing (or text). To mimic erasing, you should repaint the desired area with a white (or whatever your background color) filled rectangle.
To show and hide the target squares at regular time intervals, do not use a loop. This job can be managed via task scheduling as shown below in the sample codes.
Constraints
You can only import the following library modules: turtle, threading, random, math, sys
In many online examples of turtle graphics applications, multiple turtle objects are used on the same window. You are NOT allowed to proceed that way. Use a single turtle for all drawings.
You should follow good programming practices, for example using named constants, creating several reusable functions (top down design) and minimizing the use of global variables. A few global variables will be essential though, for example, to store the data required by multiple functions.
Suggested dimensions and locations of elements
Window size: 750 × 800
Grid Size: 700 × 700
Bottom left corner of grid: (–350, –375)
Size of target squares: Depends on size of a grid box. Leave 10 pixels margin around sides, so that squares do not touch the grid lines.
Game title text location: (–350, 345) left aligned
Start button / current square number location: (0, 345) centre aligned
Score display location (350, 345) right aligned
I am trying to move the mouse continuously with pyautogui so, I used a loop and moveTo function of pyautogui to move the mouse continuously to random points but I don't know to smooth the paths so that they don't look like intersecting lines. I found out that I can use Bezier curves but I couldn't find any explanation on how to use that.
import pyautogui
x_dim, y_dim = pyautogui.size()
for i in range(1,50):
pyautogui.moveTo(random.randint(0, x_dim), random.randint(0, y_dim), duration = 0.25)
Also is there any function that allows us to restrict our mouse movement to an element on a website?
I'm trying to port over some code from Javascript to Python, and I'm having trouble even figuring out where to start. I've looked at a good dozen tutorials for PyGame, but none of them seem to click for me. So, I was hoping to get a quick example here, or at least a point in the right direction.
I'm wanting to make a number of screens I can switch back and forth between, depending on what the user is doing at the time, and even display two side by side. At the moment, all I've got is some Javascript that draws random circles onto the screen. The PyGame logic is the only thing I'm having trouble with.
Here's my javascript for reference.
You can create a Subsurface for each subscreen that you want to create.
Then you may treat each as if it were a full screen / single surface, yet they still reference the original screen.
Pygame is a wrapper for SDL. SDL uses a surface to represent a bitmap, or anything that can be drawn on screen. With the pygame.display.set_mode((w,h),0,d) you can get the surface, or the whole canvas. You can then draw or blit the other surfaces and then call flip(), to show changes. If you wish to have a few screens, you could have a current state number, and blit the screens accordingly.
For example:
if(current_state == MAIN_SCREEN):
drawAll(screen)
else
drawEnemiesOnly(screen)
you could change the screens with the number keys:
for event in pygame.event.get():
if event.type == KEY_DOWN:
if(event.key == K_1):
current_state = 1
The script below works perfectly when I want to click, for example, the Start button on Windows, but when I try to click a button in a certain GUI program it does not have any effect.
Is it possible that this program has disabled virtual mouse clicks?
If so, can I circumvent this somehow?
import win32api, win32con
Po=win32api.GetCursorPos()
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,Po[0],Po[1],0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,Po[0],Po[1],0,0)
mouse_event (and SendInput, which is the preferred API to use for input) have a couple of tricky bits, it's a good idea to
read the MSDN page for mouse_event fully and carefully before using it - pay attention to the small print: in particular, the x and y values are not pixels, so you can't just put in values you get from GetCursorPos.
It just happens that 0,0 is the bottom-left corner, so points near the bottom left will be roughly in the same area of the screen, but the further away from that you get, the more the pixel values diverge from the actual units that this API uses: so it can appear to work for positions near the start button (assuming it's in the bottom left of the screen), but for other values, it may appear to be clicking somewhere else, which sounds similar to what you are seeing.
From MSDN:
dx [in]
Type: DWORD
The mouse's absolute position along the x-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is specified as the mouse's actual x-coordinate; relative data is specified as the number of mickeys moved. A mickey is the amount that a mouse has to move for it to report that it has moved.
So first of all, you need the MOUTEVENTF_ABSOLUTE flag. But that's not all:
Remarks
...
If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface, (65535,65535) maps onto the lower-right corner.
...so you'll need to scale your target coordinates appropriately before passing them to this API.
Mouse events generated by programs have an "injected" property that an app can filter if they want - for example MMO clients often filter those to avoid bots
Those zeros in the mouse_event let you set some properties, you might want to research if those will let you overcome the injected flag, although I can't find a way immediately
below code worked for me
pyautogui.mouseDown(fromx, fromy)
time.sleep(2)
pyautogui.mouseUp(tox, toy)
pyautogui.mouseUp(1000,400)