So I want to simulate keypresses in my testgame in less than 0.05 intervals. I used pyautogui which adds auto-pause of 0.1s between key-press which can be disabled by pyautogui.pause = 0.03 which works but you cannot use pyautogui in games and only pydirectinput works(because games use scancodes and not VK is what someone told me)
pydirectinput documentation says they have the pause function but it does not works as pydirectinput.pause= 0.03 is still greater than 0.1 is this some coding problem in their module?
how can I fix it any other module there or I myself can go do the low-level key press using pywin32 or something if it is not too hard?
It was just a problem of capitalization.
You want to use pydirectinput.PAUSE=0.03.
The PyDirectInput docs could use some love.
Like DanishDeveloper said if you browse the __init__.py file for the package you can see some definitions, for version 1.0.4 it's set as PAUSE=0.1.
import pydirectinput
def pressFast(key, N=500):
pydirectinput.PAUSE=0.01
for x in range(N):
pydirectinput.press(key)
The only thing that worked for me was going into pythons library folder and finding the _ _ init _ _ .py and in that, there is a line at the top defining the pause, you can change it there, and that changes the speed of the functions tho i dont know why the developer didnt add a simple pause function implemented.
Related
I need to mute/unmute microphone on Windows 8 by python2.7.
I find pyaudio and pymedia for interaction with sound devices, but can't find particular methods/realisations.
This can easily be achieved by using PyWin32:
import win32api
import win32gui
WM_APPCOMMAND = 0x319
APPCOMMAND_MICROPHONE_VOLUME_MUTE = 0x180000
hwnd_active = win32gui.GetForegroundWindow()
win32api.SendMessage(hwnd_active, WM_APPCOMMAND, None, APPCOMMAND_MICROPHONE_VOLUME_MUTE)
Unlike the name APPCOMMAND_MICROPHONE_VOLUME_MUTE would suggest, this actually toggles the mic
mute → unmute | unmute → mute
Here is a list of other useful parameters that can be used with WM_APPCOMMAND: WM_APPCOMMAND message (Winuser.h) - Win32 apps | Microsoft Docs
A cursory look at the pymedia documentation confirms that finding this method is hard. Pymedia does not seem to be well documented. My suggestion, without knowing anything about the library, is to look at
Mixer(<Microphone Device ID>).getControls()
This supposedly returns a dictionary with the possible controls available to the device. However, you then need to figure out which one of those you want. Documentation implies a "Volume" and "Line In" entry should exist, both of which sound plausibly useful.
Then I suppose you have to poke around the 'controls' object within that dictionary and see what is available to you, possibly using reflection because the documentation is so lacking.
The final code might look something like this:
Mixer(<Microphone Device ID>).getControls()["Line In"].control.off()
(off() is not a actual method but something like it might exist)
Hope this helps.
EDIT:
IMO this isn't a duplicate of How to toggle microphone on and off using python. That question does not actually answer anything, and instead just lists the libraries mentioned in the question. I feel like this question deserves some real code from someone more knowledgeable of the library in question.
import keyboard
import subprocess
p = subprocess.Popen(['C:\Windows\System32\mblctr.exe'])
keyboard.press_and_release('m')
p.kill()
You could use this method.
In relationship to this thread, this is also what i am kind of trying to do but i have had a bit more leeway in this.
My problem is i am currently working on a defining program (for my ti-89 titanium) to write out the definitions of variables. However, considering i had indefinite amounts of variables to add, i thought using the define function over and over again would waste memory and processing power. So my thinking was Save the variable to another variable to be defined in a later portion of the program.
prompt x
lbl x_d_r
x_d_r->q:Goto def
lbl def
define expr(q)[1]=x
where x_d_r has no assigned value. So the program was supposed to use the defined string as a list value to be x. However the obvious error came about.
So i played around on the home screen and program screen for a bit and came across entry(1) and ans(1). See back on the ti-83 (or 84) i could basically go (If i remember correctly)
disp q*1
x->ans(1)
However ans(1) on a ti-89 titanium is based upon the last answer submitted to the homescreen. Even then, ans(1) or entry(1) gets replaced in the program by just that. Lucky me, i found a way to avoid this.
Prgm
expr(char(120)&char(22)&char(97)&char(110)&char(115)&char(40)&char(49)&char(41))
EndPrgm
For those that do not know, this is simply expressing x->ans(1) which is a way for the code to transmit ans(1) within a program without removing the code to say so.
But it still does not work as a value needs to be sent to the home screen in order for it to record properly. This is one of those advantages that the ti-84 or ti-83 i wish it still had on the titanium. So i have spent some time searching for ways how i can display values of q to the home screen from within a program.
So far i learned that functions when used straight from the home screen return the value of q to the same place. However i have no way of implementing this in an actual program as the function does not wish to transmit the value to the home screen, and its rather useless within the program.
Secondly i have found this website which details methods of such ways to return values to the homescreen. While method 1 seems to hold promise, i do not seem to have any way of accessing that folder/program. Most likely because it is one that he made and has not shared its location on the pdf. I do like the expr("q"&":stop"), but q is not evaluated out so maybe i would have to rework it somehow.
While this was happening, i thought some other ideas could be using the paste key within a program but i have no idea how to implement stuff found from getkey let alone how the second and grab buttons factor in.
Or i could somehow have the ans(1) look to someplace else other than the home screen. Preferably to the i/0 screen but maybe to some other list or data matrix.
Anybody have any ideas on how to relay a value to the homescreen be it through function, pasting or something, and have the program i defined earlier define it as a value?
UPDATE+1
Ok i am beginning to question if maybe i am making it more complex than it needs to be...
After all, i am only going for just x->x_d_r[1], which is already defined elsewhere. So does it beat x->q:Goto def
Lbl def
Define expr(q)=x
(Or something like that which calls to a history recording program to define values?)
in terms of processing speed and memory count?
Got it. See here for what i was really trying to do.
So as an explanation of what the main problem was again, i wanted to be able to post a string value of q to be defined by another value of x.
The expr( function is quite a powerful tool on the ti-89 and like the person in that other forum, underestimated it. See what the person was trying to do was
InputStr "Function:",f(x)
expr(f)→f(x)
And was later answered by reworking it as
InputStr "function", n
expr(n & "->f(x)")
The expression tool just simply expresses what is in the parentheses. So during break periods in school today, i reworked in my head thinking "What if i tried rewriting the parenthesis out so it reads Expr("x->"&String(q))?
Lo-and-behold it works. Tested it with the fuller version of define to get
td()
Prgm
Prompt X
x_d_r->q
expr("x->"&string(q)&"[1]")
Disp x_d_r[1]
Delvar x_d_r
EndPrgm
Tried, tested and true. Works all the way. See what i think is happening is that anything that is not within the quotes is evaluated immediately in an expression while the the quoted objects are simply expressed and added later in response to the "&" key. Furthermore it makes sense if i was to describe it more with english; "Express x to be stored into the string of q's respective table".
While for variables sake i would have to look into ways to make x_d_r local only to the program without compensating the fact that the x_d_r portion is not considered a store value when executing x_d_r->q. But knowing what i know now i could probably do
expr("q"+"x_d_r"&->a)
expr("x->"&string(a)-"q"&"[1]")
In order to bypass that problem.
So.. I just downloaded Xojo 2014 for OS X, and up to this point have found it a pretty simple and effective development environment.
However, I've been trying to make a function or sub routine for 45 minutes. Every time I try following tutorials or the Xojo documentation I get the following error:
I've followed (even though I could be missing something) the directions here: http://docs.xojo.com/index.php/Function
Even though there is no full example in the documentation (bad development environment).
Also, in the screen shot is showing a sample function I copied and pasted off Xojo forums and is supposed to work. I'm not a programming newb per say, but more an Xojo newb. I've also had experiences with silly bugs in RealStudio in the past.
Can someone maybe point out what I could be missing?
You cannot use the Function, Sub, End Function, or End Sub lines in the method editor. Doing so will cause a syntax error because method declarations are automatically added by the IDE based on the values you enter into the method editor's name, parameters, and return type fields.
e.g.
as said,
Function, Sub, End Function, or End Sub is done for you,
you can do 'exit sub' if nothing need to be returned, else just return a proper value
like some events need a true or false, so if you need the exit the function, just return false
You cannot add inline functions within your Xojo code. You add methods to your project items these ways:
Insert->Method
"+" button on editor toolbar, then Method
Insert button on main toolbar, then Method
Option-Command-M (on OS X)
I'm trying to use IDI_INFORMATION with wxWidgets 2.8.11 (from wx/version.h) (for wxMemoryDC::DrawIcon). But first I have to load the icon: wxICON(IDI_INFORMATION) fails, LoadFile(wxT("IDI_INFORMATION")) also fails ( but LoadFile(IDI_INFORMATION) compiles and crashes, IDI_INFORMATION is a fake string pointer too tricky for wxWidgets). Hmmm, then I add some ifdefs to use Windows API: ::LoadIcon(NULL, IDI_INFORMATION) works, then wxIcon::SetHICON. While DrawIcon apparently works, the nasty surprise is that wxIcon::GetWidth, wxIcon::GetHeight return 0. Hmmm, let's get the size and use wxIcon::SetSize. Now it is finally done... wait!, but who's gonna destroy my icon? Not sure, so add the ifdef, SetHICON(NULL) and DestroyIcon.
The small question: do I have to destroy the icon myself?
The big question: is wxIcon entirely useless in this case?
PS After some debugging I discover that LoadFile(wxT("wxICON_INFORMATION")) works, wow!, but is it really multi-platform? Do I have read all the wx sources for drawing a standard icon?
The cross-platform solution is provided by wxArtProvider, just use its GetIcon() method with wxART_INFORMATION argument.
I would like to call R from within a Perl script but am having problems which I think may be a Mac thing rather than a Perl / R thing (I have Snow Leopard, and R is in the path, so no issue of Perl not finding R). I have installed the Statistics::R module but I don't think the graphics are being called properly. I have tried a very basic script (the commands work in R), but which appears to do nothing in Perl:-
use strict;
use warnings;
use Statistics::R;
my $R = Statistics::R->new();
$R->run(q`plot(c(1, 5, 10), type = "l")`);
$R->run(q`dev.off()`);
NOTE the ' are really backticks but the forum here wont post them as it thinks they are a code sample.
This produces a simple line plot in R, but just returns the command line prompt when I run the Perl script. (This is adapted from the CPAN module page http://metacpan.org/pod/Statistics::R)
Hope someone can help me.
Many thanks
Helen
I found your question intriguing, being a fellow MacR, and was not surprised that you got output from a file graphics device, png(), but not from the use of plot() without a prior call to dev.new(). It's possible, but by no means certain, that you could get R to open an interactive window in your monitor display if you entered the Mac console graphics device, quartz(). I wasn't able to tell from the documentation whether an interactive R session was being opened by Perl. What does this code produce:
use strict;
use warnings;
use Statistics::R;
my $R = Statistics::R->new();
$R->run(q`quartz()`);
$R->run(q`plot(c(1, 5, 10), type = "l")`);
$R->run(q`dev.off()`);
I also think the people who wrote that code would be interested in hearing about your progress. The linked webpages asked for feedback, and if you gave them such it might be useful to other MacRs down the line.