Created
September 22, 2012 05:49
-
-
Save TonyWhite/3765278 to your computer and use it in GitHub Desktop.
asnoW
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Inverte i movimenti del mouse | |
| * | |
| * Autore: Antonio Bianco | |
| * Versione: |0| | |
| */ | |
| import java.awt.Dimension; | |
| import java.awt.Toolkit; | |
| import java.awt.Robot; // Controlla il mouse | |
| import java.awt.MouseInfo; // Leggi le informazioni del mouse | |
| import java.awt.PointerInfo; | |
| import java.awt.Point; | |
| public class asnoW extends Thread | |
| { | |
| // Istanza di variabili | |
| private int prevX; | |
| private int prevY; | |
| private int maxX; | |
| private int maxY; | |
| private Robot r; | |
| private boolean scassaLePalle; | |
| private JClipboard clipboard; | |
| public static void main(String args[]) | |
| { | |
| new asnoW(); | |
| } | |
| /** | |
| * Constructor for objects of class asnoW | |
| */ | |
| public asnoW() | |
| { | |
| super("asnoW"); | |
| try | |
| { | |
| r = new Robot(); | |
| scassaLePalle = true; | |
| clipboard = new JClipboard(); | |
| clipboard.toClipboard(""); | |
| Dimension dimensioniSchermo = Toolkit.getDefaultToolkit().getScreenSize(); // Legge le dimensioni dello schermo | |
| maxX = dimensioniSchermo.width - 1; | |
| maxY = dimensioniSchermo.height - 1; | |
| } | |
| catch (Exception e) | |
| { | |
| System.out.println("Impossibile inizializzare la classe Robot.\nProkramma kapùtt"); | |
| System.exit(1); | |
| } | |
| PointerInfo info = MouseInfo.getPointerInfo(); | |
| Point punto = info.getLocation(); | |
| prevX = (int)punto.getX(); | |
| prevY = (int)punto.getY(); | |
| this.start(); | |
| } | |
| public void run() | |
| { | |
| while(scassaLePalle) | |
| { | |
| try | |
| { | |
| // Legge la posizione attuale del mouse | |
| PointerInfo info = MouseInfo.getPointerInfo(); | |
| Point punto = info.getLocation(); | |
| int x = (int)punto.getX(); | |
| int y = (int)punto.getY(); | |
| // Si è spostato? Dove? | |
| if ((x!=prevX)||(y!=prevY)) | |
| { | |
| int differenzaX = x-prevX; | |
| prevX = prevX-differenzaX; | |
| int differenzaY = y-prevY; | |
| prevY = prevY-differenzaY; | |
| // Non bisogna avvicinarsi ai bordi (ecessario solo per Windows) | |
| if (prevX<1) prevX=1; | |
| else if (prevX>maxX-1) prevX=maxX-1; | |
| if (prevY<1) prevY=1; | |
| else if (prevY>maxY-1) prevY=maxY-1; | |
| r.mouseMove(prevX, prevY); | |
| } | |
| // Esce dall'applicazione | |
| if (clipboard.fromClipboard().equals("Geek rulez")) | |
| { | |
| this.interrupt(); | |
| System.exit(0); | |
| } | |
| Thread.sleep(1); | |
| } | |
| catch(Exception e) | |
| { | |
| // Nope | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.datatransfer.*; | |
| import java.awt.*; | |
| public class JClipboard implements ClipboardOwner | |
| { | |
| /** | |
| * Incolla nella Clipboard | |
| */ | |
| public void toClipboard(String contenuto) | |
| { | |
| StringSelection st = new StringSelection(contenuto); | |
| Clipboard cp = Toolkit.getDefaultToolkit().getSystemClipboard(); | |
| cp.setContents(st, this); | |
| } | |
| /** | |
| * Legge il testo dalla clipboard di sistema | |
| */ | |
| public String fromClipboard() | |
| { | |
| String contenuto = null; | |
| Clipboard cp = Toolkit.getDefaultToolkit().getSystemClipboard(); | |
| Transferable contents = cp.getContents(null); | |
| boolean hasTransferableText = (contents != null) && contents.isDataFlavorSupported(DataFlavor.stringFlavor); //Se c'è il contenuto ed è una stringa | |
| if (hasTransferableText) | |
| { | |
| try | |
| { | |
| contenuto = (String)contents.getTransferData(DataFlavor.stringFlavor); | |
| } | |
| catch(Exception e){} | |
| } | |
| return contenuto; | |
| } | |
| public void lostOwnership(Clipboard clip, Transferable tr){} | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment