I got my script to work with typing out keys, but for some reason, those keys do not work in Minecraft. Although, typing Minecraft messages in the chat are no problem. I'm trying to get python to move my own character.
In my script, I tried to use pyautogui, the mouse in Minecraft works but not keys such as w, a, s, or d. Is there another import or way to hold down a key that actually works in Minecraft?
def hold_W (hold_time):
start = time.time()
while time.time() - start < hold_time:
pyautogui.press('w')
Doing this and calling it worked for writing texts, but for some reason does not register in Minecraft? Any help?
If you used "Automate the Boring Stuff With Python" to learn this stuff, the book states that pyautogui cannot be used on video games on Windows. I am not sure how to fix this, but the link to the book is here: https://automatetheboringstuff.com/2e/chapter20/
Also, you can go to the documentation of pyautogui here: https://pyautogui.readthedocs.io/en/latest/ to see if the games feature has been added. My greatest regrets that I cannot solve this problem for you. If it makes you feel better, pyautogui does work on .io games.
Different video games have different ways of detecting keystrokes, so to find a thing that will work on all video games you might need to get your hands dirty and do some stuff I have no clue how to do.
Related
I have programming as a subject in school, and this is our last project of the semester. For our last task we are going to use replit.com, which use PygameZero. Which from my understanding, is a easier version of Pygame, which again is a version of python more focused on making games (correct me if im wrong).
I want to make a Street Fighter type game, and because of that i really want to use two controller for it (because i want a PvP game). I have searched, but the turorials i find are for Pygame, and i can't find any for Pygame Zero. Either that, or it is some semi-advanced stuff that i don't understand. If anyone knows how to connect controllers to Pygame Zero, it would help a ton!
And if controllers matter, i have Xbox One controllers, a switch pro controller and a gamecube controller (whith a gamecube to usb adapter). Allthough i mainly want to use the xbox controllers if thats possible.
thanks so much in advance!
PS: Im relativly new to programming, so i would really apreciate if you could dumb down your answers to the point that i can understand it!
Pygame Zero does support controllers and PS4 and Xbox One controllers both work.
This book is a great resource for beginners in Python who want to make games in Pygame Zero. It also has some more information on joysticks here and here.
Also regarding Sembei Norimaki's comment, you basically have to try and see if the code in sixAxis.py at that website works with your controller. See the bottom of the file and edit it to see if you can get it to work.
I've been trying to bind my up, down, left and right keys on my keyboard to certain clicks on my screen. I am an absolute noob at Python so I'm really struggling to get it done but it seems like a nice little project to get better at coding.
I was wondering if anybody has some general tips on what libraries, etc. I should be using for this task?
I am by the way on a Mac laptop if that matters.
Thanks in advance!
Use the 'pynput' module to read keypresses and map them to the functions you want to create using an if statement.
Looks like you want to create hotkeys, refer to this video for a detailed explanation: https://www.youtube.com/watch?v=n_dfv5DLCGI
I am creating a game using Python and tkinter, and when I tried to add some music, the function making the music stopped the rest of the script (and also the window).
So I need to create a new thread I think to play the audio and keep the window working...
I tried some things making errors, not running, or stopping the window, I currently have :
window.after(2000,showText,"Text 1")
window.after(2000,playSound,"Sound 1.wav")
window.after(7000,showText,"Text 2")
Important detail : the playSound function returns nothing, so nothing needs to wait for it.
I also don't know much about programming in Python, I prefer using LUAU.
Try using the module threading. I found this article very useful for understanding the core concepts and setting up my first multithreaded program
I found another article telling exactly how to make it work and it now works.
The article is probably in french, but I give the link : http://www.xavierdupre.fr/app/teachpyx/helpsphinx/c_parallelisation/thread.html
I have a laser pointer that I'm using along with my webcam as a drawing tablet, but I'd like to use the extra buttons on it too. They seem to be bound to Page Up, Page Down, Escape, and Period. I can't seem to figure out a way to get the input(which is handled like it's a keyboard) without any windows being selected.
I've tried serial and pyusb, but I've had issues with both of those. I got it to work with Pygame, but as far as I know, you can't receive input without the window it creates being selected. Any ideas?
You could try making a python key-logger. However, it would be much easier to just use Pygame.
CodeSurgeon answered me in a comment.
Looks like there are a lot of youtube tutorials on the subject, surprisingly. This one shows a cross-platform approach using the pynput module, while this one looks to be using a windows-specific approach (pyhook and pythoncom). Can't vouch for either of these as I just found them through some searching, and I am sure there are others as well.
I found that pynput works for me. (Windows 10/Python 3.4)
Does anybody know if it's possible to press the play button on a music website using Python? What I'm trying to do is make an alarm clock script that plays a random playlist on a music site.
Here and here are similar questions (I think), although I don't know if what I'm using applies to this. I'm trying to use Grooveshark.
The first linked question's answer, to use Selenium, is probably your best bet. You can write your code in Python, and any other way of interfacing with a website as complex as Grooveshark will probably not be easy. There is an API (http://developers.grooveshark.com) but for what you want Selenium is probably the easiest approach.
just use tkinter button widget and use pygame musicplayer, it works very well.