I have a program that wants to be able to click on the screen; say my screen is X by Y pixels, I want to make my program send clicks to coordinate (x, y). Any language is acceptable, but preferably Ruby, Java, or Python :)
Preferably on Windows, Ubuntu is another possibility.
Thanks for the help.
With Ubuntu:
from Xlib import X, display
disp = display.Display()
screen = disp.screen()
root = screen.root
root.warp_pointer(300, 300)
disp.sync()
So as a function:
from Xlib import X, display
def MoveMouse(x, y):
disp = display.Display()
screen = disp.screen()
root = screen.root
root.warp_pointer(x, y)
disp.sync()
I'll edit in click functionality in a little bit...
Holy cow, just look at the help(root)! You can draw things, change the cursor, fiddle with windows, and kill X!
I'm using this for my own purposes...
I would give a short answer to your question, but I believe that this article here explains things a lot better than I would and would be much more beneficial. It's in Java and goes over the Robot class which is good for input simulations, mainly for things such as tech demos where the robot class substitutes for real user input. It's fairly in depth, short, and is a really easy read. Hope you enjoy!
Related
I'll try to explain my question as much as possible but feel free to ask any question if something is unclear.
I have my main program which handles everything, but I want a second window to show stuff like output and messages. This second screen will be underneath the first one and will only display text.
A example would be a game like hangman. Where my first window would should the letters and figure and the second screen would show messages like "That letter wasn't right. 3 Tries left." or something similar.
I know you can use
navigateToURL(new URLRequest("external.swf"), "_blank");
To get a second swf to load. But that isn't really what I'm looking for.
So long story short:
I need a two windows for 1 program. Is this possible or should I make two programs that somehow interact with one another.
Any information or links to helpful site would be very appreciated.
Thanks in advance.
Since you are using adobe Air you can create more windows:
var options:NativeWindowInitOptions = new NativeWindowInitOptions();
options.systemChrome = NativeWindowSystemChrome.STANDARD;
options.type = NativeWindowType.UTILITY
options.transparent = false;
options.resizable = false;
options.maximizable = false;
var newWindow:NativeWindow = new NativeWindow(options);
newWindow.activate();
This does mean you can't use this on the web though.
Edit: Take a look at this.
I think a better solution would be using Adobe Air Workers. You layout your views as you wish, but the communication will be threw the workers API. The biggest benefits of workers is that they are using different threads of GPU and dramatically improve your performance.
I'm writing a program for a college course. I import a .PPM file saved as a 2-d array from main into the function. Then I have to update the pixels of a graphics window (which is opened in main) using .setPixel and color_RGB() method and functions.
The pixels are updating, however there is a white pixel in between each colored pixel for some reason. It's not the PPM file (they were supplied by my professor and I've tried multiple ones), so it has to be my function.
Warning: I am not allowed to use anything in my program that we have not yet covered in our course (it's a first year, 4 month course so the scope is not massive). I don't need to know exactly HOW to fix it, as much as I need to know why it's doing it (AKA: I need to be able to explain how I fixed it, and why it was breaking in the first place).
Here is my function:
def Draw_Pic(pic,pic_array, sizeX, sizeY, gfx_window):
for y in range(sizeY):
for x in range(0, sizeX, 3):
pixel_color = color_rgb(pic_array[y][x],pic_array[y][x+1],pic_array[y][x+2])
pic.setPixel(x,y,pixel_color)
gfx_window.update()
You are using range(0, sizeX, 3) which creates a list with values 0 to sizeX with increment 3.
So your x goes 0..3..6..9 etc. Makes perfect sense for the part where you assemble pixel color from 3 components, but then you do pic.setPixel(x,y,colors) using the same interleaved x.
Hope that helped.
P.S. By the way, why "colors" and not "color"?
edit Also, that way you'll copy only 1/3 of the image in pic_array.
I have been developing a software package to plot astronomical data in the form of a movie. It looks like this.
To do this, I export 100 tables of data from Java to gnuplot and use a bash script to turn them into a GIF. I want instead to do it in HTML and maybe Raphael.
I'm thinking that I can use a Python script to iterate through folders and build a hundred plots, and then cycle through them. Any ideas on this? How can I get them to cycle?
You will have to test performance issues, but FLOT might be just the thing for you...
here is an example of flot animating:
http://people.iola.dk/olau/flot/examples/realtime.html
I think a canvas is what you need. Just draw all the points, clear the canvas, and redraw
your code would look something like this pseduo code
for each frame
for each point
canvas.draw point at x, y
end
clear canvas
end
Even I was looking for something similar, I found this one link will be trying it out http://humblesoftware.com/flotr2/
I wonder if you could/would help me.
I have a page (java script/ html5/webgl)
and I am displaying a set of points,
then when the user pressess on a point I would lik to find the x and y coordinates that I set in the first place.(range of 0 to 1)
what I get from the even is the x and y screen coordinates (pixals)
from even.offsetX and so.
what is the right math to get to the acsual points?
please help
In regular OpenGL, the command you need is gluUnProject:
http://www.opengl.org/sdk/docs/man/xhtml/gluUnProject.xml
For WebGL, you will have to roll your own since it doesn't have any fixed function pipeline support. Assuming that you are using standard transformation matrices, you can just modify the formulas in that man page. It would be hard to say anything more specific without the details of you set up your coordinate systems.
I'm playing around a bit with ActionScript. What I want is that I can display a mathematical function from a string.
E.g. in my working python script I do something like that:
formula = 'x**2 + 3*x'
for x in range( 0, 100 ):
y = eval( formula )
graph.display( x, y )
I want to port this to ActionScript, but it seems like there is no more eval since version 3. How can I compute my function values anyway?
Something that might also work in your case, is using Javascript eval instead. You can use something like:
var result = ExternalInterface.call(myEvalFunctionInJS,formula)
to evaluate math functions.
This is an somewhat easy and useful workaround as javascript is quite close to actionscript.
If you put the ExternalInterface call inside an loop, it may become sluggish. To avoid that, you can write the loop in javascript. (You can even write the entire javascript inside as3, so that you do not need to touch the actual html page.)
edit:
Here's an link for that.
http://www.actionscript.org/resources/articles/745/2/JavaScript-and-VBScript-Injection-in-ActionScript-3/Page2.html
You will have to write an eval yourself. You will have to parse the string and invoke the right operators.
Here's a link to get you started.
The Tamarin project has a ECMAScript parser written in ES4. Try this as well.
"You can even write the entire javascript inside as3, so that you do not need to touch the actual html page." Do you have links / tutorials? – okoman
Both AS and JS are based on the same ECMAScript standard. So, if you pass a string of AS3 to a container, and use JS's eval on this string, it should work just fine.
Just noticed this question and realized I answered almost the exact same thing here: https://stackoverflow.com/a/11460839/1449525
To paraphrase myself, you can definitely use D.eval, AS3Eval, or ExternalInterface (as seen in the currently chosen answer) assuming you're running in a web page. However, all it seems like you really need is something like this simple MathParser (More info about the MathParser)
Here's how you'd use the MathParser:
package {
import bkde.as3.parsers.*;
import flash.display.Sprite;
public class MathTest extends Sprite {
public function MathTest() {
var parser:MathParser = new MathParser([]);
var compiledObj:CompiledObject = parser.doCompile("(10/3)*4+10");
var answer:Number = parser.doEval(compiledObj.PolishArray, []);
var xyParser:MathParser = new MathParser(["x", "y"]);
var xyCompiledObj:CompiledObject = xyParser.doCompile("(x/3)*y+10");
var xyAnswer:Number = xyParser.doEval(xyCompiledObj.PolishArray, [10, 4]);
}
}
}
I'm sure ExternalInterface stuff works just fine, but I have personal reservations about the cross language communication (especially in terms of efficiency and security) as well as just the awkward nature of it. I feel like a wholly-contained, same-language solution is typically preferable in most situations.
A bit late, but for reference, the D.eval library does what you are asking for:
http://www.riaone.com/products/deval/
It is free and works great for me, but doesn't come with source. I found this question looking for an alternative built-in or source-available solution.
There is also a seemingly abandoned project to port Tamarin to Flash itself:
http://eval.hurlant.com/
Would be awesome if more progress was made, but seems like a curiosity for now.