-1

Im using wamp on localhost, so I want to use PHP to pass two coordinates as arguments to a Java program which will move my cursor to those coordinates on screen. Am I correct in assuming this will work or is the program run in a different scope which wouldn't be able to move my cursor?

I know you can execute commands in php but I'm wondering if moving the cursor is possible.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
user2936448
  • 335
  • 4
  • 16

4 Answers4

1

PHP can run programs (including java programs) using the command line. So, if you are able to create such a program, yes, it could be run by PHP if it´s running on localhost as you said.

0

You are running your PHP on the server, also there's your java application, which can be invoked via php-script.

But the cursor runs in client browser's window (not in the server context) and it is not possible to do this via way you described.

If you wish to handle cursor movement use javascript on the web-page that opened by the client.

0

PHP can execute Java programs but they will be run on server, just like any other PHP code. So, your current approach to solve the problem won't work because both application will run on server and you want to achieve functionality that only works on client. Of course, if the only client for your application will be localhost, then it will work, but note that it won't work when performing the method on any other client.

Since you cannot achieve such functionality using javascript, there's no way for a web application to handle it. The only odd way to achieve it would be through a Java applet, but this mean that your clients will need Java installed in their PCs.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • if the server is localhost (as he said it is) it could, yes, be done – bovino Marcelo Bezerra Jul 11 '14 at 15:36
  • @MarceloBezerra there's no point on deploying a web application to be used on localhost only... – Luiggi Mendoza Jul 11 '14 at 15:36
  • In general i agree with you, but there maybe exceptions that depends A LOT of context. – bovino Marcelo Bezerra Jul 11 '14 at 15:37
  • @MarceloBezerra I cannot see a real world context when this applies. Seriously. And if you achieve it locally, you're lying to yourself because that won't work when being put on production. – Luiggi Mendoza Jul 11 '14 at 15:39
  • 2
    This web application is meant for localhost only. Meaning that I want the php script to execute a Java program that directly affects my computer – user2936448 Jul 11 '14 at 15:39
  • @user2936448 why do you want such kind of application? Why not write a desktop application instead? If it is for curiosity purposes, then let me tell you you won't gain something very useful. Anyway, it's up to you. – Luiggi Mendoza Jul 11 '14 at 15:42
  • @LuiggiMendoza I'll briefly explain the application. It's a greasemonkey script which scrapes a certain live website for data. It then sends this data to a localhost PHP script which process it. I need the PHP script to execute a mouse movement if possible. This will only be used on my localhost computer and my intention isn't for it to be set live. – user2936448 Jul 11 '14 at 15:53
  • @user2936448 from your explanation, it is not clear why do you need to move the cursor. If you want to simulate usage of the page, then you should use another tools that already handle this work instead. For example, you have Selenium that works with Java. – Luiggi Mendoza Jul 11 '14 at 16:51
  • @LuiggiMendoza I need to have my local PHP server run a java program on my machine that can move the mouse, click, and unclick the mouse. That's all my question is. – user2936448 Jul 11 '14 at 17:02
  • @user2936448 and you already have 4 answers. We cannot help you more with that. – Luiggi Mendoza Jul 11 '14 at 17:02
0

You say you run your server on localhost, so that could indicate that you don't care if the cursor is moved on the server or on the client. Assuming that, moving cursor on server from PHP is easy:

  1. Create a java program that moves cursor to coordinates set via the arguments of the main(String[] args) method.

  2. Call that from your php as exec("java MoveMouse $x $y") or something.

How to move cursor on client is more complicated, since JavaScript can't move mouse cursor so you would have to use a java applet or something.

Community
  • 1
  • 1
kajacx
  • 12,361
  • 5
  • 43
  • 70
  • That's my question. How do I get this java applet that moves the cursor to be launched with arguments from the PHP script. this is my issue. – user2936448 Jul 11 '14 at 15:55
  • `how to pass parameters from html to java applet` - you can follow this - http://www.cafeaulait.org/course/week5/16.html - tutorial or many others. – kajacx Jul 11 '14 at 16:00
  • Just to be clear, the mouse moves on the clients computer. This will work correct? – user2936448 Jul 11 '14 at 17:03
  • Yes, according to this: http://stackoverflow.com/questions/1321999/i-want-to-use-robot-class-in-java-applet-for-web-browser-will-it-move-and-click you can move mouse on client using a java applet. – kajacx Jul 11 '14 at 17:34