How detect touch when i use on_click - python

Hi how can I detect my touch with touchframe?
The first time the mouse worked OK when I connected my frame, touched the cursor ran and clicked. But this code fragment event didn't work. Why? How can I change the code to detect the touch event?
def on_click(x,y,button,pressed):
print("mouse click")
playerOff()
listener.stop()

Related

win32api.getasynckeystate detect mouse.click from pynput

i am making a autoclicker and i face a problem:
mouse = Controller() while true: if win32api.GetAsyncKey(0x01)&0x8000 > 0: mouse.click(Button.left)
when i hold left click it works but only click one time because it reset the mouse state. I would like to know how i can simulate a click without triggering getasynckey.
The autoclicker has to click when i hold left click.I tried pynput listener, pygame listener and pyautogui.leftclick() but none of these works.
thanks you.

Python Mouse click simulate halts program until you press CTRL+C

I'm just trying to simulate a mouse click every second but once the first click starts, the program just completely halts and I have no idea why
The program will continue if I press CTRL+C but then it halts again after it clicks:
import pyautogui
import time
while True:
time.sleep(1)
print("Clicking")
pyautogui.click()
And it doesn't matter which mouse library I use to simulate the click, it always halts. It should be clicking every second without interruption. What's wrong?
The only reason i think it does so is because it clicks at some place where it is not supposed to(by default the position is your current mouse pointer), so the pyautogui.click() takes 2 parameters x,y try specifying the the exact coordinate and it should work. To find the coordinates of a position place your mouse pointer there and run pyautogui.position().

on_key_press() events blocking on_mouse_press() an on_mouse_motion() events for 1 second

So I'm developing a small game in Pyglet and I have across this weird behavior which I don't know how to solve. It seems like a Pyglet bug, but it's weird that I cannot find others users reporting this problem.
The problem is that after a key is pressed, if I left click right after the key press, the event is ignored. This is repeatable, always. What's funny is that if I right click, the event is always working fine. Only left click is the problem. Also on_mouse_motion() is blocked for 1 second after any key is pressed. If I don't press any keyboard keys, all mouse events work just fine.
I have tested this with Pyglet versions 1.3.0, 1.4.10 and 1.5.11 and all have the same behavior. I also tested this on 2 different computers and behavior is the same. I also tried with Vsync ON and OFF and with mouse exclusive to pyglet window. Using Windows 10 and Python 3.7.4-64b.
Here is a simple code to reproduce the problem, just press a key and then left click within 1 second:
import pyglet
window = pyglet.window.Window()
#window.event
def on_key_press(symbol, modifiers):
print('A key was pressed')
#window.event
def on_mouse_press(x, y, button, modifiers):
print('Mouse event')
pyglet.app.run()
EDIT: The problem is the Synaptics touchpad which is configured to disable the touchpad during typing on laptops.
It seems the problem is the Synaptics touchpad which is configured to disable the touchpad during typing on laptops:
https://superuser.com/questions/399341/touchpad-does-not-respond-when-i-am-holding-key-on-the-keyboard
I connected an external mouse to the laptop and the problem is gone.

Is there a way to detect the pygame display window being moved by user?

I am writing a game using Pygame. When the game window opens, I currently only have the program call pygame.display.update after the game has changed something that shows on the screen. That works fine for limiting screen refreshes to only when necessary. I have discovered a side effect of moving the game window that causes the screen to get corrupted, which requires the program to force a refresh even if the program itself doesn't require one.
My question is if there is a pygame event (I didn't see one) or something else, that I can use to force the game to refresh the screen after a window move.
Okay, I happened across a code snippet that reports events to the console here:
http://www.poketcode.com/en/pygame/events/index.html
Running this was useful because I noticed that every time I moved the window partially off-screen, pygame triggered a VideoExpose event when the window area moved back on screen.
So, I added the following bit of code to my event loop and it worked great!:
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.VIDEOEXPOSE:
game.update_panels(force=True)
game.update_panels(force=False)

Key Press Connect at Start of Execution

I have a Python 3.6.3 script that incorporates PyQt5. The GUI has a button that toggles play and pause of a video file. Pressing the spacebar also toggles play and pause. The button works fine all the time. The spacebar also works as intended, except at the very start of executing the script. I need to click some other event first (such as a button or slider bar) before the spacebar will correctly triggers the signal to pause or play the video. I want to start playing the video with the spacebar when the script starts up. Here is how I create the connections in the same __init__(self) function . As you can see, clicking on the button and pressing the spacebar both connect the signal to the same function (self.pauseVideo).
self.btnPause = QtWidgets.QPushButton(self.centralwidget)
self.btnPause.clicked.connect(self.pauseVideo)
self.spacebar = QShortcut(QKeySequence(Qt.Key_Space), self)
self.spacebar.activated.connect(self.pauseVideo)
Suggestions on how to get the spacebar to trigger the signal when the script first starts?
After a lot more searching, reassigning keyboard shortcuts (without success), etc., I found this post PyQt widget keyboard focus. I inserted
self.setFocusPolicy(Qt.StrongFocus)
into __init__(self) and it seemed to solve my problem! Now I'm just hoping it doesn't cause other issues.

Categories