james..

i check the speed at internet ...

it is really what i expected...

i little bit speed than my own apps...good:)

but i fiddling with mouse event with your code can you ...

can you help me in your way how do send keyboard and mouse event from client side(screenwatcher) to server(screen sender..)

my apps have it own but when i implement your idea..i missed something ...

plz help me..

then if will come to conclusion we will close this thread with confirmation from clawsy...:)

can you help me in your way how do send keyboard and mouse event from client side(screenwatcher) to server(screen sender..)

I'm currently working on a simple addon to send mouse clicks and keyboard presses to the server. I'll post what I've got so far - but it's not complete and not properly tested. In particular I think I may have a thread locking problem at the server between using Robot for screen capture and for mouse/key events on different threads, but I really don't know yet.
So, at your own risk, this is what I've got so far...
At the client I add the following mouse and keyboard listeners to the JLabel that displays the screen ("out" is tha buffered data output stream)

@Override
	public void mousePressed(MouseEvent e) {
		// System.out.println("Mouse button " + e.getButton() + " pressed at " +
		// e.getX() + "," + e.getY());
		try {
			out.writeInt(MOUSE_PRESSED);
			out.writeInt(e.getButton());
			out.writeInt(e.getX());
			out.writeInt(e.getY());
			out.flush();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// System.out.println("Mouse button " + e.getButton() + " released at " +
		// e.getX() + "," + e.getY());
		try {
			out.writeInt(MOUSE_RELEASED);
			out.writeInt(e.getButton());
			out.writeInt(e.getX());
			out.writeInt(e.getY());
			out.flush();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}

	@Override
	public void keyPressed(KeyEvent e) {
		// System.out.println("Key " + e.getKeyCode() + " pressed");
		try {
			out.writeInt(MOUSE_LAST + 1);
			// my code for key released (shouldn't clash with mouse codes)
			out.writeInt(e.getKeyCode());
			out.flush();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {
		// System.out.println("Key " + e.getKeyCode() + " released");
		try {
			out.writeInt(MOUSE_LAST + 2);
			// my code for key released (shouldn't clash with mouse codes)
			out.writeInt(e.getKeyCode());
			out.flush();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}

Then at the server I have a thread listening to the data input stream...

public void run() {
			try {
				while (keepRunning) {
					int messageType, x, y, keyCode;
					messageType = in.readInt();
					switch (messageType) {
					case MOUSE_PRESSED:
						int button = in.readInt();
						x = in.readInt();
						y = in.readInt();
						System.out.println("Mouse button " + button + " press at " + x + "," + y);
						robot.mouseMove(x, y);
						robot.mousePress(convertButtonCode(button));
						break;
					case MOUSE_RELEASED:
						button = in.readInt();
						x = in.readInt();
						y = in.readInt();
						System.out.println("Mouse button " + button + " release at " + x + "," + y);
						robot.mouseMove(x, y);
						robot.mouseRelease(convertButtonCode(button));
						break;
					case (MOUSE_LAST + 1):  // private code for key pressed
						keyCode = in.readInt();
						System.out.println("Key " + keyCode + " pressed");
						robot.keyPress(keyCode);
						break;
					case (MOUSE_LAST + 2): // private code for key released
						keyCode = in.readInt();
						System.out.println("Key " + keyCode + " released");
						robot.keyRelease(keyCode);
						break;
					default:
						System.out.println("Unknown remote control code " + messageType);
					}
				}
			} catch (IOException e) {
				e.printStackTrace();
			}

		}

Because the mouse events use different button codes from the Robot class, I also needed this:

int convertButtonCode(int keyCode) {
			// converts MouseEvent button codes to Robot button masks
			switch (keyCode) {
			case BUTTON1:
				return BUTTON1_MASK;
			case BUTTON2:
				return BUTTON2_MASK;
			case BUTTON3:
				return BUTTON3_MASK;
			}
			return 0;
		}

So, I don't know if that's any help to you, but it does work (mostly).
Please share any fixes or improvements you make
J.
ps: sory about the excessive indenting - I use Eclipse witha 3-char tab indent and don't have time now to tidy the code for DaniWeb

ok james i trying with your idea if i got i will post codes ...


what i suggest is...

in server side we determine x,y coordination by the following...

//mouse event...

        final int x =( ScreenRect.x)+(int) (evt.getX());
    	final int y = (ScreenRect.y) + (int) (evt.getY() );
        rt.mouseMove(x,y);

        int buttonMask = 0;
        int buttons = evt.getButton();
        if ((buttons == MouseEvent.BUTTON1)) buttonMask = InputEvent.BUTTON1_MASK;
        if ((buttons == MouseEvent.BUTTON2)) buttonMask |= InputEvent.BUTTON2_MASK;
        if ((buttons == MouseEvent.BUTTON3)) buttonMask |= InputEvent.BUTTON3_MASK;     
        switch(evt.getID()) {         
            case MouseEvent.MOUSE_PRESSED: rt.mousePress(buttonMask); break;
            case MouseEvent.MOUSE_RELEASED: rt.mouseRelease(buttonMask); break;
            case MouseEvent.MOUSE_WHEEL: rt.mouseWheel(
                    ((MouseWheelEvent) evt).getUnitsToScroll()); break;
        }          
    }
    
//keyboard event...

    public void applyKeyEvent(KeyEvent evt) {
        switch(evt.getID()) {
            case KeyEvent.KEY_PRESSED: rt.keyPress(evt.getKeyCode()); break;
            case KeyEvent.KEY_RELEASED: rt.keyRelease(evt.getKeyCode()); break;

so just we pass this coordination ( x,y) from client to server..

we determine this x,y by positioning at JLABEL...

SO FAR I HAVE THIS IDEA ....

Hi musthafa.
The code I posted gets the coords from the JLabel mouseevent and and passes them as two ints to the server. That part works OK, even when the JLabel is being scrolled in a JScrollPane. You will see that there's no need to convert the origin as your code does on lines 3,4.

sorry james can you send the solution with mouse event...

i also fiddling :@ with make thread synchronizing...


then i will check it...

sorry james can you send the solution with mouse event....

#O already did. It's the first code sample in post #92
Those are the methods for the mouse and keyboard listeners.

commented: Good stuff! James. +7

yes the method i know and tried it before post #92...

but the problem is thread and anonymous class...

so can you send demo.zip again with those method implemented...

or else send it to my inbox...

ca:Sn you please...

I have that code incorporated into a much larger application, so it's not in the demo that I built earlier. However, the mouse/keyboard listeners are absolutely straightforward, as is the server thread. You should be able to do those yourself without my help!
J

ok James...

i will try...

i think you,clawsy and me are too busy and concentrate on different works..

so can we windup this discussion?

thanks buddy for your time and help...

definitely i add your names in my apps as courtesy...

thank you:)

hi James...

so far i tried this nothing happened...

Yeah... I have a lot of studies to do... the only thing I would ask James is: if I revert to PNG system when image gets big...
1. Can I determine the image size before your RLE processing? Cause I have to know whether I use RLE or PNG encoding to send the image.
2. I still don't know how to make the pixels transparent when I send the PNG. I determine which pixel changes and if not... i make it 0 (pixel=0). So, on the other side I get those pixels black, not transperent. I thought I somehow have to decode that 0 value from the PNG buffered imahe at the client and make it transparent... any ideas?

Yeah... I have a lot of studies to do... the only thing I would ask James is: if I revert to PNG system when image gets big...
1. Can I determine the image size before your RLE processing? Cause I have to know whether I use RLE or PNG encoding to send the image.
2. I still don't know how to make the pixels transparent when I send the PNG. I determine which pixel changes and if not... i make it 0 (pixel=0). So, on the other side I get those pixels black, not transperent. I thought I somehow have to decode that 0 value from the PNG buffered imahe at the client and make it transparent... any ideas?

clawsy still you getting any delay...

because James suggested us in right way..

that's why i preferred James idea...

cause i got james idea and it is working well..

you getting blank screen at clien side or what..

I just had a quick look... can't see where you start the delegate thread in the server!

I just had a quick look... can't see where you start the delegate thread in the server!

ScreenServer(Socket clientSocket, int targetRefreshInterval) {
		// targetRefreshInterval is the desired interval (in mSecs) between
		// starting refreshes. (0 means continuous updates.)
		// Actual rate is not guaranteed.
		// Eg targetRefreshInterval = 2000 means try to refresh every 2 seconds

		try {

			robot = new Robot();
			Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
			width = screenSize.width;
			height = screenSize.height;

			System.out.println("Serving at refresh interval "
					+ targetRefreshInterval + "mSec");

			out = new DataOutputStream(new BufferedOutputStream(clientSocket
					.getOutputStream()));
			out.writeInt(width);
			out.writeInt(height);
			new ServerDelegate(clientSocket,robot);//here
			this.targetRefreshInterval = targetRefreshInterval;
			setPriority(Thread.MIN_PRIORITY);
			start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

is anything wrong james..

So basically I would need to know the size of the image to know when to go with the PNG system and then to know how to decode the PNG to draw transparent pixels instead of that black pixels. James knows about this from my previous posts.

@musthafa: OK, sorry. I';m afraid you're going to have to debug this one yourself - I have no free tine at the moment. Good luck.
@clawsy: I think that trying to decide PNG vs incremental RLE on the fly will be very difficult. I was suggesting that it may be good to use the PNG ImageIO method just for the initial image.That needs no transparency etc, and will give the starting Image and buffers that the incremental method can then continue with.
J

@musthafa: OK, sorry. I';m afraid you're going to have to debug this one yourself - I have no free tine at the moment. Good luck.
@clawsy: I think that trying to decide PNG vs incremental RLE on the fly will be very difficult. I was suggesting that it may be good to use the PNG ImageIO method just for the initial image.That needs no transparency etc, and will give the starting Image and buffers that the incremental method can then continue with.
J

its ok james..

i will try myself..

i think i have done something very blindly..:-/

ok i look it now...

I suggest I should close this thread and mark it as solved as the differences of the image were found, and fast and optimized solution was used...
For the transmision and other stuff new threads can be started...
If you think I souldn't close it, tell me... I will wait until you answer.

I suggest I should close this thread and mark it as solved as the differences of the image were found, and fast and optimized solution was used...
For the transmision and other stuff new threads can be started...
If you think I souldn't close it, tell me... I will wait until you answer.

ok clawsy i agreed..

thank you lot to james and clawsy!!!!!!!!!!!:icon_mrgreen:

I agree. It's been fun, hasn't it?
J

Yeah, sure real fun and a lot of ideas and coding :). Thanks you guys for all :).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.