Java clipboard as stack in paste override -
i have done research, no useful results found.
here deal, i'm writing 'new' clipboard works stack instead of 'area'. , i'm brave or stupid enoght in java. far in tests see if possible have managed create stack behavior. problem i'm getting sometimes, when paste top of stack (pop operation), doesn't pop or other reason pastes twice.
example: if copy 3 words: carlos, lucas, eastwood stack clipboard behaves @ paste: eastwood, eastwood, lucas, carlos
i'm using jnativehooks reading system keypresses , determining when user pasting. think happening system pasting before code... well, here code anyway (it test, explains why badly commented):
import java.awt.toolkit; import java.awt.datatransfer.clipboard; import java.awt.datatransfer.transferable; import java.util.stack; import org.jnativehook.globalscreen; import org.jnativehook.nativehookexception; import org.jnativehook.nativeinputevent; import org.jnativehook.keyboard.nativekeyevent; import org.jnativehook.keyboard.nativekeylistener; public class test3 implements nativekeylistener { clipboard sysclip = toolkit.getdefaulttoolkit().getsystemclipboard(); stack<transferable> clipstack = new stack<>(); public static void main(string[] args) { try { globalscreen.registernativehook(); } catch (nativehookexception ex) { system.err .println("there problem registering native hook."); system.err.println(ex.getmessage()); system.exit(1); } test2 t2 = new test2(); // construct example object , initialze native hook. globalscreen.getinstance().addnativekeylistener(t2); } @override public void nativekeypressed(nativekeyevent ev) { // copy if (ev.getkeycode() == nativekeyevent.vk_c && nativeinputevent.getmodifierstext(ev.getmodifiers()).equals( "ctrl")) { // clip pop try { thread.sleep(100); } catch (interruptedexception e) { e.printstacktrace(); } clipstack.push(sysclip.getcontents(null)); system.out.println("ctrl+c : stack(" + clipstack.size() + ")"); } // paste if (ev.getkeycode() == nativekeyevent.vk_v && nativeinputevent.getmodifierstext(ev.getmodifiers()).equals( "ctrl")) { // clip pop try { thread.sleep(100); } catch (interruptedexception e) { e.printstacktrace(); } if (clipstack.size() > 1) { sysclip.setcontents(clipstack.pop(), null); } else sysclip.setcontents(clipstack.peek(), null); system.out.println("ctrl+v : stack(" + clipstack.size() + ")"); } } @override public void nativekeyreleased(nativekeyevent e) { } @override public void nativekeytyped(nativekeyevent e) { } }
i think same suggested.
have copy , paste key combination different ctrl+c
, ctrl+v
, can bypass using system clipboard. push selected text , pop text directly text pointer in application provided of course using stack behavior particular application.
the system retains it's own copy of latest clip , gets duplicate sysclip.setcontents(clipstack.pop(), null)
on paste operation.
i don't have idea on disabling system behavior. can research on that. can make sure it's problem changing key combination.
Comments
Post a Comment