I was making a python project that could play online games and i had a problem. I wanted to make the computer create a user but to do so you had to write in a name. I tried using ctypes but that didnt work out because i couldnt find any way to write letters, only click and move the cursor. Does anyone know a way to make python take control over keyboard? I am thinking something like this:
import ctypes
import webbrowser
webbrowser.open("www.url.com")
ctypes.key.a()
ctypes.key.c()
ctypes.key.c()
ctypes.key.enter()
I would recommend pyautogui. It is as simple as pyautogui.press('b').
Related
Hi I was wondering if anyone could answer my question, how would I go about making a game with graphics in python instead of text based games.
I'm only new though so if it involves another programming language then I'm probably can't do it yet.
Use tkinter module inside of python. To do this simply add from tkinter import * at the start of your program and open a window and use a mainloop to close it at the end. You can research how to use tkinter online on various different websites. I would suggest effbot as it's very useful for tkinter basics.
I would recommend using the tkinter library. You can makes games with graphics instead of text. One example would be here. And it is just Python :)
I was wondering if anyone knows how to import a sprite and let it move when pressing the arrow keys in python, without using pygame, or some other library. This is purely out of curiosity, because I was just thinking about some sort of personal challenge, and that's what came to mind: a python game, without the help of pygame or libtcod. Is this possible, or do you need a library to do this for you? I'd appreciate anyone's input on this one.
Thanks.
What comes to my mind is using Tkinter's Canvas class. It is quite possible to do a simple program like that described using bindings on this class.
A good example of this may be found in Mark Lutz's Programming Python (http://shop.oreilly.com/product/9780596158118.do), the Moving Pics example.
If you don't own this, you can still look at the code for it as a reference by downloading the code using the link on the right side of the page. The path to the appropriat folder is /PP4E-Examples-1.3.1/Examples/PP4E/Gui/MovingPics/.
I am learning both autohotkey and python. I wrote this script in ahk (and it works!) that automatically joins tables (using tableninja) in the pokerstars client--
^q::
Loop
{
Send q
Sleep 500
Send {PgUp}
Sleep 500
Send w
Sleep 60000
}
return
I'd like to convert this into python--could you give me an idea as to which modules I can use to accomplish this?
What the python script needs to do is to (while looping) type in a letter (on a notepad that's already open), go down two lines, type in another letter, then wait one minute before starting over.
I am thinking--
import module to auto-type letters
import module that works as timer
def function
type letter q
enter
enter
def function
type letter w
def function
sleep
while True
function
function
function
I am teaching myself how to code. I haven't reached that part about python modules just yet. Thanks!
Assuming you work on windows(don't think AHK runs on anything else), you should check out sendkeys. It will make sending keystrokes a piece of cake. If you want somthing a little more robust, take a look at pywinauto
For the shortcut part, take a look at pyhook
I suggest these modules:
SendKeysCtypes for any sending of keystrokes and sending shortcuts to a window.
SendKeysCtypes is a new and more stable version of SendKeys. I have had issues with SendKeys in the past.
PYHK to deal with global hotkeys - receive hotkeys and trigger functions.
PYHK is based on pyHook and makes hotkey registration very simple. I wrote it because I had the exact same idea as you - I wanted to to do AHK functionality in python.
win32gui for window handling such as moving resizing.
I personally prefer win32gui for short, simple tasks. I use pywinauto for more complex tasks. An example would be if I had to access a menu within a program (like File-New).
mouse.py to control the mouse. This is the most robust way I have found so far. The version I use is an extension of a module I found here at stackoverflow - ctypes mouse_events.
I have personally done several programs for poker with python. I have released source code of my smaller programs. You can find them with source on my website schurpf.com/poker-software.
there's also AutoPy, a cross-platform library for this purpose.
How can I do it, even if my application.exe is not the focused window ?
For example, like the Windows+D shortcut... Works everywhere...
I want that ALT+1 does a function, ALT+2 does another one, and so on...
You mean like this?
You need to use pyHook.
I have a pyHook example on my site. http://fadedbluesky.com/2011/using-pyhook-to-block-windows-key/
I originally wrote this to block keys in a game written using pygame. You should be able to easily adapt it to other windows programs.
I'm pretty new to programming, and I'm creating a simple text-based game.>
I'm wondering if there is a simple way to create my own terminal-type window with which I can place coloured input etc.
Is there a graphics module well suited to this?
I'm using Mac, but I would like it to work on Windows as well
Thanks
The Tkinter Text Widget will do what you ask. the IDLE main window is implemented as one, if you want to play with an example.
You could use the termcolor library - it that what you're looking for?
On Windows things are trickier. See this SO answer - you should resort to win32console and some ctypes. The answer has some code and links to other articles.
For game programming with Python, I would always recommend PyGame.
It is not very complex and enables you to easily use input, graphics and sound.
As a start:
http://www.penzilla.net/tutorials/python/pygame/