bradvido commented on issue #3962:
URL: https://github.com/apache/netbeans/issues/3962#issuecomment-1664507172

   I whipped this together quickly. It reproduces the issue every time for me 
on a vanilla netbeans 18 install with JDK17.
   All it does it copy/paste between netbeans and notepad.
   
   Here's an example/screen recording. It works on the first copy/paste 
attempt, and the subsequent 4 fail:
   https://capture.dropbox.com/aL3a0aLjMzAGqbz0
   
   
   Not sure exactly how you want me to contribute this, so just putting it here 
for now
   ```
   package copypastetest;
   
   import java.awt.Robot;
   import java.awt.event.KeyEvent;
   
   public class CopyPasteTest {
   
       int maxTries = 5;
   
       public static void main(String[] args) {
           /*
               Put cursor inside this comment block before running.
               
            */
           try {
               new CopyPasteTest();
           } catch (Exception x) {
               x.printStackTrace();
           }
       }
   
       private final Robot robot;
   
       public CopyPasteTest() throws Exception {
           robot = new java.awt.Robot();
   
           //open notepad, give it some time to get focus, and write our 
starting text
           Runtime.getRuntime().exec("notepad");
           Thread.sleep(1500);
           writeText("sometext");
   
           for (int tryNum = 1; tryNum <= maxTries; tryNum++) {
               copyLine();//copy from notepad
               enter();//go to next line in notepad (to prep for next paste)
               altTab();//go to netbeans
               paste();//paste into netbeans
               writeText(String.valueOf(tryNum));//add try num to the text in 
netbeans
               copyLine();//copy from netbeans
               enter();//go to next line in netbeans (to prep for next paste)
               altTab();//go to notepad
               paste();//paste into notepad
           }
   
       }
   
       private void writeText(String text) {
           for (char c : text.toCharArray()) {
               int keyCode = KeyEvent.getExtendedKeyCodeForChar(c);
               _press(keyCode);
               _release(keyCode);
           }
       }
   
       private void copyLine() {
           //highlight this line
           _press(KeyEvent.VK_END);
           _release(KeyEvent.VK_END);
           _press(KeyEvent.VK_SHIFT);
           _press(KeyEvent.VK_HOME);
           _release(KeyEvent.VK_HOME);
           _release(KeyEvent.VK_SHIFT);
   
           //copy highlighted text
           _press(KeyEvent.VK_CONTROL);
           _press(KeyEvent.VK_C);
           _release(KeyEvent.VK_C);
           _release(KeyEvent.VK_CONTROL);
   
           //remove highlight, put cursor at end of line
           _press(KeyEvent.VK_END);
           _release(KeyEvent.VK_END);
   
       }
   
       private void paste() {
           _press(KeyEvent.VK_CONTROL);
           _press(KeyEvent.VK_V);
           _release(KeyEvent.VK_CONTROL);
           _release(KeyEvent.VK_V);
       }
   
       private void enter() {
           _press(KeyEvent.VK_ENTER);
           _release(KeyEvent.VK_ENTER);
       }
   
       private void altTab() {
           _press(KeyEvent.VK_ALT);
           _press(KeyEvent.VK_TAB);
           _release(KeyEvent.VK_ALT);
           _release(KeyEvent.VK_TAB);
           try {
               Thread.sleep(1000);//breathing room for windows
           } catch (InterruptedException ex) {
               ex.printStackTrace();
           }
       }
   
       private void _press(int e) {
           robot.keyPress(e);
           try {
               Thread.sleep(200);
           } catch (InterruptedException ex) {
               ex.printStackTrace();
           }
       }
   
       private void _release(int e) {
           robot.keyRelease(e);
           try {
               Thread.sleep(200);
           } catch (InterruptedException ex) {
               ex.printStackTrace();
           }
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to