Posted by
shantanu yadav
on
- Get link
- X
- Other Apps
//code by quadgen //this code hack the clipboard import java.awt.*; import java.awt.datatransfer.*; class HackTheClipboard { static String text = "Your text here"; public static void main(String args[]) { while(true) { Clipboard clipboard ; StringSelection stringSelection = new StringSelection(text); try{ clipboard=Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, stringSelection); } catch(Exception e) { /*error may occur if the user and the program both will try to access
clipboard at the same time just let the code to compile as the clipbrd may be free after
some time */
continue;
} } } }
import java.awt.*; import java.awt.datatransfer.*; public class ClipboardImage { /** * Place an image on the system clipboard. * * @param image - the image to be added to the system clipboard */ public static void write(Image image) { if (image == null) throw new IllegalArgumentException ("Image can't be null"); ImageTransferable transferable = new ImageTransferable( image ); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(transferable, null); } static class ImageTransferable implements Transferable { private Image image; public ImageTransferable (Image image) { this.image = image; } public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { if (isDataFlavorSupported(flavor)) { return image; } else { throw new UnsupportedFlavorException(flavor); } } public boolean isDataFlavorSupported (DataFlavor flavor) { return flavor == DataFlavor.imageFlavor; } public DataFlavor[] getTransferDataFlavors () { return new DataFlavor[] { DataFlavor.imageFlavor }; } } public static void main(String[] args) { while(true) { try{ Image image = Toolkit.getDefaultToolkit ().createImage("C:\\Users\\LENOVO-PC\\Downloads\\2.jpg"); ClipboardImage.write( image ); Thread.sleep(1000);//when working with images loop // needed to be stopped for some time in order to store the image } catch(Exception e) { continue; } } } }
Comments
Post a Comment