I am trying to get my script to simulate pressing "CTRL+1" at the end so that the Chrome Browser jumps back to the first tab open - Once the main script is finished.
I have been using the robot class? not sure if this is the best thing to be using or not!
This is what I have, but not sure of correct or where to insert it?
<script>
    function trimAndCopyHandler(event) {
        // The barcode input text box
        const barcodeBox = event.target
            // The barcode input string
        const barcodeText = barcodeBox.value
        // if the string is shorter than 22 chars then exit
        if (barcodeText.length < 22) return
        const start = 6 // start index in string
        const end = 20 // end index in string
        // Select the text field
        barcodeBox.select()
        barcodeBox.setSelectionRange(start, end)
        // assign extracted section of barcode to trimmedString
        const trimmedString = barcodeText.slice(start, end)
        // Copy the trimmedString
        navigator.clipboard.writeText(trimmedString)
        // using template strings `${my variable here}`
        //alert(`Copied ${trimmedString} to clipboard`)
        alertTimeout(`Shipment No. ${trimmedString} Copied!`,2000)
        // clear the text box
        barcodeBox.value = ''
    }
    // find and assign the trim button element to 'trimAndCopyButton'.
    const barcode = document.querySelector('#barcode')
    // add a listener to the barcode element, which fires
    // onchange and executes the trimAndCopyHandler
    barcode.addEventListener('change', trimAndCopyHandler)
    document.getElementById('barcode').focus();
    function alertTimeout(mymsg,mymsecs)
{
 var myelement = document.createElement("div");
myelement.setAttribute("style","background-color: yellow color:red; width: 800px;height: 200px;position: absolute;top:0;bottom:0;left:0;right:0;margin:auto;border: 0px solid black;font-family:arial;font-size:30px;font-weight:bold;display: flex; align-items: center; justify-content: center; text-align: center;");
 myelement.innerHTML = mymsg;
 setTimeout(function(){
  myelement.parentNode.removeChild(myelement);
 },mymsecs);
 document.body.appendChild(myelement);
}
  
 
</script>
<script>
//Wait for 1 sec
Thread.sleep(1000);
Robot robot = new Robot();
        
        //Press CTRL key 
        robot.keyPress(KeyEvent.VK_CONTROL);
        //Press 1 , it gets typed as CTRL key is pressed
        robot.keyPress(KeyEvent.VK_1);
        
        robot.keyPress(KeyEvent.VK_1);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        
         
        
</script>
