Detecting an arbittrary button press on a USB joystick WITHOUT pygame - python

Is there anyway I could register button pushes on a joystick without using any function from pygame?

If you're looking for a way to do it with just the standard Python library, the answer is probably "no" - or at the very least, "not in any straightforward manner". There are many things in the standard library, but gaming hardware support is not one of them.

If your on linux, you could check out Python Joystick Class using Gobject

Related

Win32API Mouse vs Real Mouse Click

I have recently started using win32api to simulate mouse events and was wondering if it was at all detectable?
For example, does the api follow the exact same process/run the exact same commands as if done when using a real mouse - or are there some slight differences which can be detected? Furthermore, is this the same case with win32com SendKeys (via Shell Script/Python)?
I ask, because in the past I have had a few applications detect the Java robot library - but they all seem to work fine when using the Python win32api. Thanks.
The SendInput function will insert input events into the same queue as a hardware device but the events are marked with a LLMHF_INJECTED flag that can be detected by hooks. To avoid this flag you probably have to write a custom driver.

Difference between pyglet and pygame, in simple words?

There are many questions dealing with pyglet and pygame, but what I want to know is difference in theses two, in simple terms.
Not in technical terms, not experimental features and all that.
They are both libraries, both API, both for creation of games and multimedia apps, right?
Just in plain English, for someone like me, relative begginer, who has finished course about Python in Codecademy and read Head first Python book.
Pyglet is a wrapper around OpenGL, while Pygame is wrapper around SDL.
OpenGL is primarily concerned with 3d rendering, while SDL
is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D.
PyGame is low-level library. You have to do all on your own - starting at mainloop and all functions called by mainloop. You can do it in different ways.
(And you can learn something about mainloops in Pyglet, Tkinter, PyQt, wxPython and other GUIs, not only in Python)
Pyglet is framework - it has already mainloop and you can't change it and you can't see how it works. You override functions which mainloop calls. You have to keep its rules.
I've tried pyglet and pygame and rate pygame as the best .

How to simulate a real keyboard's keypress in Python/PyQt?

I need to write a virtual keyboard for typing texts, I'm planning to use Python and Qt (PyQt) library for this task. problem is I don't know how to simulate KeyPress not as internal Qt event, but as simulation of a real keyboard so I could work with this keyboard as like with real one - interacting with application on my computer. I can't find anything in Qt documentation about this. So is there any way to do it through PyQt/Qt, or I need to use some Python library, and which exactly?
I understand that this is a PyQt question, but at the request of the OP will give a c++ example in case it helps in finding the Python solution.
On the c++ side simulating the keyboard is done by posting keypress events to the application's event loop. These may be considered 'internal Qt events', but are the exact same interface as would be received for a physical key press. They are accomplished as follows:
QKeyEvent *event = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Enter);
QCoreApplication::postEvent (receiver, event);
Looking through the PyQt QCoreApplcation API, the postEvent function also exists, so it should be possible to do something analagous (unfortunately I can't offer an example as I'm unfamiliar with writting python scripts).
I had the same problem.
Pyautogui is very good for this and it is stupid simple.
import pyautogui
pyautogui.typewrite("the stuff")
Or if you want to actually simulate pressing a literal keypress use:
import pyautogui
pyautogui.keypressDown("the stuff")
pyautogui.keypressUp("the stuff")
Here's the documentation: https://pyautogui.readthedocs.org/en/latest/
Hope this helps.

Using Touchpad gestures in wxPython?

I am trying to create an app using wxPython that has a side swipe gesture in it i.e. on the Mac touchpad. I had a search around and I can't find any reference to multitouch support in wx. Does anybody know if there is a class that will allow me to get this input? Much appreciated.
Multi-touch really isn't supported. If the touch can be translated to just normal mouse events, then wx can support that. So theoretically wx should support a swipe but you'll have to do it yourself by watching EVT_MOTION and checking which direction the mouse movement is going in.
See also the following links:
https://groups.google.com/forum/?fromgroups=#!topic/wxpython-users/E4SMMUPwgNI
http://pymt.eu/

Media Play/Pause Simulation

My keyboard contains a row of buttons for various non-standard keyboard tasks. These keys contain such functions as modifying the volume, playing or pausing, and skipping tracks. How can I simulate a basic play/pause with Python? I am on Windows, by the way.
I would use pywin32. Bundled with the installation is a large number of API-docs (usually placed at something like C:\Python32\Lib\site-packages.) It essentially wraps a lot of stuff in the Win32-library which is used for many low-levels tasks in Windows.
After installing it you could use the wrapper for keybd_event.
You could also use SendInput instead of keybd_event but it doesn't seem to be wrapped by PyWin32. SendMessage is also an option but more cumbersome.
You'll need to look up the virtual scan code for those special buttons, since I doubt the char-to-code mapping functions will help you here. You can find the reference here.
Then it is a simple matter of calling the function. The snippet below pauses Chuck Berry on my computer.
>>> import win32api
>>> VK_MEDIA_PLAY_PAUSE = 0xB3
>>> hwcode = win32api.MapVirtualKey(VK_MEDIA_PLAY_PAUSE, 0)
>>> hwcode
34
>>> win32api.keybd_event(VK_MEDIA_PLAY_PAUSE, hwcode)
MapVirtualKey gives us the hardware scan code which keybd_event needs (or more likely, the keyboard driver.)
Note that all this is snapped up by the keyboard driver, so you don't really have any control where the keystrokes are sent. With SendMessage you can send them to a specific window. It usually doesn't matter with media keys since those are intercepted by music players and such.
This was not working for me on Windows 10 64, all recent updates installed. I needed this (the 3rd parameter 2) before it'd work.
win32api.keybd_event(0xB3,0,2,0)
didn't bother looking into why it works, but threw it out there since this and other similar posts had me frustrated as for some reason not working on my PC.
This successfully paused/played Amazon Music on my PC.
You can use pyautogui. This library contains a lot of keyboard and mouse simulations.
To install run pip install pyautogui in cmd.
In order to simulate a play/pause keypress, you should use pyautogui.press("playpause").
Check out their docs at https://pyautogui.readthedocs.io/en/latest/keyboard.html to see the list of the supported keys and some other keyboard functions.

Categories

Resources