Keyboard frozen after script run --- need to press ctrl-alt-c

Asked by Chetan B

HI,

I have run a script using sikuli to lauch a command prompt and do some operations and close it.

Once the script execution is over keyboard will be freezed,if we press any keyboard key,it doesnt work.

If we manually press keyboard with hot key CTRL+ALT+C keys,then it will be fine.

Please do provide us the solution to it.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Chetan B
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

should first be a question

Revision history for this message
RaiMan (raimund-hocke) said :
#2

what version of SikuliX?

How do you open the command prompt?

Are you typing into the command prompt?

Revision history for this message
Chetan B (chetan0147) said :
#4

Hi ,

Sorry i sent wrong code,please find correct code below:

package Devicetesting;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.FileUtils;
import org.apache.commons.net.util.Base64;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Key;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;
import org.testng.Reporter;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class SikuliCommand extends Base1 {
    public static String line = null;
    public static String actualresult = "";
    public static String expectedresult =
"df09020000000023edc2330870f8e7100010048e0890b3d51f300100000002007c17010902000700000500000b0200010700000500010b030040bd8052c1021076bffaad8520be7092354574d8d391";
    public static int i;
    public static boolean flag = false;
    @Test
    public static void Sikuli() throws IOException,
InterruptedException, FindFailed, AWTException {

        try {
            Screen screen = new Screen();

            // Runtime.getRuntime().exec("C:\\Windows\\System32\\cmd.exe");

            // App app=new App("notepad.exe");
            // App.open("C:\\Windows\\System32\\cmd.exe");
            Robot robot = new Robot();

            robot.keyPress(KeyEvent.VK_WINDOWS);

            robot.keyPress(KeyEvent.VK_R);
            robot.keyRelease(KeyEvent.VK_WINDOWS);
            robot.keyRelease(KeyEvent.VK_R);
            Thread.sleep(2000);
            screen.type("C:\\Windows\\System32\\cmd.exe");
            robot.keyPress(KeyEvent.VK_ENTER);

            Pattern commandprompt1 = new
Pattern("C:\\Sikulinotepad\\Commandprompt.png");
    /*
    Pattern commandprompt1 = new Pattern("C:\\Sikulinotepad\\Notepadedit.png");
    Pattern commandprompt2 = new Pattern("C:\\Sikulinotepad\\Notepadpaste.png");
    Pattern commandprompt3= new Pattern("C:\\Sikulinotepad\\Notepadfile.png");
    Pattern commandprompt4 = new
Pattern("C:\\Sikulinotepad\\Notepadsaveas.png");
    Pattern commandprompt5= new
Pattern("C:\\Sikulinotepad\\Notepadfilepath.png");
    Pattern commandprompt6 = new
Pattern("C:\\Sikulinotepad\\Notepadfilesave.png");
    Pattern commandprompt7= new Pattern("C:\\Sikulinotepad\\Notepadfile.png");
    Pattern commandprompt8= new
Pattern("C:\\Sikulinotepad\\Notepadfilexit.png");
    Pattern commandprompt9= new Pattern("C:\\Sikulinotepad\\Confirmsaveas.png");
    // screen.click(commandC:prompt0);
C:
      Thread.sleep(2000);
        screen.click(commandprompt1);
        screen.click(commandprompt2);
        screen
*/
            Thread.sleep(3000);
            screen.click(commandprompt1);

            screen.type("title firstcommandprompt");
            robot.keyPress(KeyEvent.VK_ENTER);
            screen.type("cd/");

            robot.keyPress(KeyEvent.VK_ENTER);
            screen.type("cd dist-db-17-08-2018");
            robot.keyPress(KeyEvent.VK_ENTER);
            screen.type("acb-r2.0.exe entityfile_00-0F.yaml 9089");
            robot.keyPress(KeyEvent.VK_ENTER);
            //====================================================================
            //secondcommandprompt

            robot.keyPress(KeyEvent.VK_WINDOWS);

            robot.keyPress(KeyEvent.VK_R);
            robot.keyRelease(KeyEvent.VK_WINDOWS);
            robot.keyRelease(KeyEvent.VK_R);
            Thread.sleep(2000);
            screen.type("C:\\Windows\\System32\\cmd.exe");
            robot.keyPress(KeyEvent.VK_ENTER);

            Thread.sleep(3000);
            screen.click(commandprompt1);

            screen.type("title Secondcommandprompt");
            robot.keyPress(KeyEvent.VK_ENTER);
            screen.type("cd/");
            robot.keyPress(KeyEvent.VK_ENTER);
            screen.type("cd dist-db-17-08-2018");
            robot.keyPress(KeyEvent.VK_ENTER);
            screen.type("echo %date%-%time%");
            robot.keyPress(KeyEvent.VK_ENTER);
            screen.type("receive.exe 21020");
            robot.keyPress(KeyEvent.VK_ENTER);

            //Third command prompt

            robot.keyPress(KeyEvent.VK_WINDOWS);

            robot.keyPress(KeyEvent.VK_R);
            robot.keyRelease(KeyEvent.VK_WINDOWS);
            robot.keyRelease(KeyEvent.VK_R);
            Thread.sleep(2000);
            screen.type("C:\\Windows\\System32\\cmd.exe");
            robot.keyPress(KeyEvent.VK_ENTER);

            Thread.sleep(3000);
            screen.click(commandprompt1);

            screen.type("title Thirdcommandprompt");
            robot.keyPress(KeyEvent.VK_ENTER);
            screen.type("cd/");
            robot.keyPress(KeyEvent.VK_ENTER);
            screen.type("cd dist-db-17-08-2018");
            robot.keyPress(KeyEvent.VK_ENTER);
            screen.type("send.exe 127.0.0.1 9089 gcs23.yaml");
            robot.keyPress(KeyEvent.VK_ENTER);
            Thread.sleep(2000);
            robot.keyPress(KeyEvent.VK_ALT);
            robot.keyPress(KeyEvent.VK_TAB);
            Thread.sleep(2000);
            robot.keyRelease(KeyEvent.VK_TAB);
            robot.keyRelease(KeyEvent.VK_ALT);
            Thread.sleep(4000);

            for (int i = 0; i <= 0; i++) {
                robot.keyPress(KeyEvent.VK_CONTROL);
                robot.keyPress(KeyEvent.VK_A);
                robot.keyPress(KeyEvent.VK_CONTROL);
                robot.keyPress(KeyEvent.VK_C);
                robot.keyRelease(KeyEvent.VK_CONTROL);
                robot.keyRelease(KeyEvent.VK_A);
                robot.keyRelease(KeyEvent.VK_C);

                Thread.sleep(3000);

                Runtime.getRuntime().exec("C:\\Windows\\system32\\Notepad.exe");

                // C:\Users\bodkec1\Pictures\img
                Pattern commandprompt0 = new
Pattern("C:\\Sikulinotepad\\opennotepad.png");
                Pattern commandprompt11 = new
Pattern("C:\\Sikulinotepad\\Notepadedit.png");
                Pattern commandprompt2 = new
Pattern("C:\\Sikulinotepad\\Notepadpaste.png");
                Pattern commandprompt3 = new
Pattern("C:\\Sikulinotepad\\Notepadfile.png");
                Pattern commandprompt4 = new
Pattern("C:\\Sikulinotepad\\Notepadsaveas.png");
                Pattern commandprompt5 = new
Pattern("C:\\Sikulinotepad\\Notepadfilepath.png");
                Pattern commandprompt6 = new
Pattern("C:\\Sikulinotepad\\Notepadfilesave.png");
                Pattern commandprompt7 = new
Pattern("C:\\Sikulinotepad\\Notepadfile.png");
                Pattern commandprompt8 = new
Pattern("C:\\Sikulinotepad\\Notepadfilexit.png");
                Pattern commandprompt9 = new
Pattern("C:\\Sikulinotepad\\Confirmsaveas.png");
                // screen.click(commandprompt0);

                Thread.sleep(2000);
                screen.click(commandprompt11);
                screen.click(commandprompt2);
                screen.click(commandprompt3);
                screen.click(commandprompt4);
                // screen.click(commandprompt5);

                Thread.sleep(3000);
                screen.type(Key.DELETE);

                screen.type("C:\\Responses\\gcs23.txt");
                Thread.sleep(1000);

                screen.click(commandprompt6);
                screen.click(commandprompt9);
                Thread.sleep(2000);
                screen.click(commandprompt7);
                screen.click(commandprompt8);

                String fileName = "C:\\Responses\\gcs23.txt";
                int counter = 0;

                FileReader fileReader = null;

                fileReader = new FileReader(fileName);
                BufferedReader bufferedReader = new BufferedReader(fileReader);
                while ((line = bufferedReader.readLine()) != null) {
                    counter++;
                    if (line.contains("FullData")) {
                        flag = true;
                        System.out.println("Base64" + line);
                        line = line.toString();
                        actualresult = line.substring(14);
                        System.out.println(actualresult);
                        break;
                    }

                }
                if (flag == true) {

                    break;

                }

            }
            if (flag == false) {

                robot.keyPress(KeyEvent.VK_ALT);
                robot.keyPress(KeyEvent.VK_ENTER);
                Thread.sleep(3000);
                String timeStamp = new
SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
                BufferedImage image = new
Robot().createScreenCapture(new
Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
                ImageIO.write(image, "png", new
File("C:\\Screenshots\\Failed\\Gcs23.png"));

                robot.keyPress(KeyEvent.VK_ALT);
                robot.keyPress(KeyEvent.VK_ENTER);
                Pattern commandprompt9 = new
Pattern("C:\\dist-db-17-08-2018\\Sikuli\\Command.png");
                Pattern commandprompt10 = new
Pattern("C:\\dist-db-17-08-2018\\Sikuli\\closeall.png");

                screen.rightClick(commandprompt9);
                screen.click(commandprompt10);

                Thread.sleep(3000);

                robot.keyPress(KeyEvent.VK_ALT);
                robot.keyPress(KeyEvent.VK_CONTROL);
                robot.keyPress(KeyEvent.VK_C);
                Thread.sleep(2000);

                // Runtime.getRuntime().exec("rundll32
user32.dll,LockWorkStation");
                SoftAssert assert1 = new SoftAssert();
                assert1.fail();
                assert1.assertAll();
                robot.keyPress(KeyEvent.VK_ALT);
                robot.keyPress(KeyEvent.VK_CONTROL);
                robot.keyPress(KeyEvent.VK_C);

            }
            //String guid =
"3QAAAAAAAEERAAAAAN8JAgAAAAAj5axnCHD45xAAEASOCJCz1R8wAQAAAAIAoQ0BCQEBBwkABQgACwCLAHQUrYRoxljDjduMFw==";
            byte[] decoded = Base64.decodeBase64(actualresult);
            String Actualresult = Hex.encodeHexString(decoded);
            System.out.println("Actual Result in Hexadecimal" + Actualresult);
            // Reporter.log("Actual Result:" + Actualresult);

            String expectedresult1 = expectedresult.substring(0, 8);

            String expectedresult2 = expectedresult.substring(24, 40);

            String expectedresult3 = expectedresult.substring(42, 58);

            String Actualresult1 = Actualresult.substring(0, 8);
            System.out.println("expectedresult1" + expectedresult1);
            System.out.println("Actualresult1" + Actualresult1);

            String Actualresult2 = Actualresult.substring(24, 40);
            System.out.println("expectedresult2" + expectedresult2);
            System.out.println("Actualresult2" + Actualresult2);

            String Actualresult3 = Actualresult.substring(42, 58);
            System.out.println("expectedresult3" + expectedresult3);
            System.out.println("Actualresult3" + Actualresult3);
            if (Actualresult1.replaceAll("\\s+",
"").contains(expectedresult1.replaceAll("\\s+", "")) &&
(Actualresult2.replaceAll("\\s+",
"").contains(expectedresult2.replaceAll("\\s+", "")) &&
(Actualresult3.replaceAll("\\s+",
"").contains(expectedresult3.replaceAll("\\s+", ""))))) {
                System.out.println("Expected Result Matches with the
actual result");

System.out.println("========================================================");
                System.out.println("Actual Result1:" + Actualresult1);
                System.out.println("Expected Result1:" + expectedresult1);

System.out.println("========================================================");
                System.out.println("Actual Result2:" + Actualresult2);
                System.out.println("Expected Result2:" + expectedresult2);

System.out.println("========================================================");
                System.out.println("Actual Result3:" + Actualresult3);
                System.out.println("Expected Result3:" + expectedresult3);

System.out.println("========================================================");

                Reporter.log("Expected Result Matches with the actual result");

Reporter.log("========================================================");
                Reporter.log("Actual Result1:" + Actualresult1);
                Reporter.log("Expected Result1:" + expectedresult1);

Reporter.log("========================================================");
                Reporter.log("Actual Result2:" + Actualresult2);
                Reporter.log("Expected Result2:" + expectedresult2);

Reporter.log("========================================================");
                Reporter.log("Actual Result3:" + Actualresult3);
                Reporter.log("Expected Result3:" + expectedresult3);

Reporter.log("========================================================");

                String timeStamp = new
SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
                File screenshot = ((TakesScreenshot)
screen).getScreenshotAs(OutputType.FILE);
                FileUtils.copyFile(screenshot, new
File("C:\\Screenshots\\Passed\\Gcs23" + timeStamp + ".png"));
                Reporter.log(timeStamp);
                SoftAssert assert1 = new SoftAssert();
                assert1.assertEquals("pass", "pass");
                assert1.assertAll();

            } else {
                System.out.println("Actual result does not match with
expected result");
                String timeStamp = new
SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
                File screenshot = ((TakesScreenshot)
screen).getScreenshotAs(OutputType.FILE);
                FileUtils.copyFile(screenshot, new
File("C:\\Screenshots\\Failed\\Gcs23" + timeStamp + ".png"));
                SoftAssert assert1 = new SoftAssert();
                assert1.fail();
                assert1.assertAll();

            }

        } catch (FileNotFoundException ex) {
            System.out.println(ex);
            SoftAssert assert1 = new SoftAssert();
            assert1.fail();
            assert1.assertAll();

        }

    }

    public static void main(String args[]) throws IOException,
InterruptedException, FindFailed, AWTException {

        SikuliCommand.Sikuli();
    }

}

Regards,

Chetan

Hi,

Yes I type in command

On Fri, Mar 15, 2019, 11:57 AM RaiMan <email address hidden>
wrote:

> Your question #679226 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/679226
>
> Status: Open => Needs information
>
> RaiMan requested more information:
> what version of SikuliX?
>
> How do you open the command prompt?
>
> Are you typing into the command prompt?
>
> --
> To answer this request for more information, you can either reply to
> this email or enter your reply at the following page:
> https://answers.launchpad.net/sikuli/+question/679226
>
> You received this question notification because you asked the question.
>

Revision history for this message
Chetan B (chetan0147) said :
#5

I open 3 command prompts using

     Robot robot = new Robot();

            robot.keyPress(KeyEvent.VK_WINDOWS);

            robot.keyPress(KeyEvent.VK_R);
            robot.keyRelease(KeyEvent.VK_WINDOWS);
            robot.keyRelease(KeyEvent.VK_R);
            Thread.sleep(2000);
            screen.type("C:\\Windows\\System32\\cmd.exe");
            robot.keyPress(KeyEvent.VK_ENTER);

do some operations and then open notepad and save some data and close all command prompt and notepad.

This is the complete process i do.

After the code execution is done ,when i type anything in my keyboard,none of the keys will work.
After press CTRL+ALT+C combination keyboard beomes normal.

Revision history for this message
RaiMan (raimund-hocke) said :
#6

the only thing I can see, is that you are mixing the SikuliX AWT Robot (type()) with your own Robot instance.

Not sure what that might do.

Why don't you use the SikuliX features like

type("r", Key.WIN)

instead of
  robot.keyPress(KeyEvent.VK_WINDOWS);
            robot.keyPress(KeyEvent.VK_R);
            robot.keyRelease(KeyEvent.VK_WINDOWS);
            robot.keyRelease(KeyEvent.VK_R);

BTW: 1.1.2 is no longer supported for such special cases.
Use 1.1.4 snapshot

Revision history for this message
Chetan B (chetan0147) said :
#7

If am using robot class of java to open run command and launch command
prompt
Using Sikuli i am not able to launch cmd.exe using App.open

On Fri, Mar 15, 2019 at 2:52 PM RaiMan <email address hidden>
wrote:

> Your question #679226 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/679226
>
> Status: Open => Answered
>
> RaiMan proposed the following answer:
> the only thing I can see, is that you are mixing the SikuliX AWT Robot
> (type()) with your own Robot instance.
>
> Not sure what that might do.
>
> Why don't you use the SikuliX features like
>
> type("r", Key.WIN)
>
> instead of
> robot.keyPress(KeyEvent.VK_WINDOWS);
> robot.keyPress(KeyEvent.VK_R);
> robot.keyRelease(KeyEvent.VK_WINDOWS);
> robot.keyRelease(KeyEvent.VK_R);
>
> BTW: 1.1.2 is no longer supported for such special cases.
> Use 1.1.4 snapshot
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/sikuli/+question/679226/+confirm?answer_id=5
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/sikuli/+question/679226
>
> You received this question notification because you asked the question.
>

Revision history for this message
RaiMan (raimund-hocke) said :
#8

--- If am using robot class of java to open run command and launch command prompt

I have seen that of course.

That is why I asked:
Why don't you use the SikuliX features like

type("r", Key.WIN)

instead of
  robot.keyPress(KeyEvent.VK_WINDOWS);
            robot.keyPress(KeyEvent.VK_R);
            robot.keyRelease(KeyEvent.VK_WINDOWS);
            robot.keyRelease(KeyEvent.VK_R);

the idea is to get rid of your own Robot instance.

Revision history for this message
Chetan B (chetan0147) said :
#9

Hi,

After removing robot class of java ,issue got solved.

Thanks a lot.

PLease let me know how to launch cmd.exe using sikuli command.

Regards,
Chetan

Revision history for this message
RaiMan (raimund-hocke) said :
#10

until now I did not find an option to start a command prompt using App open.

I will make this a request bug (command prompt open, focus and close)

The easiest way:
type("r", Key.WIN)
wait(1)
type("cmd" + Key.ENTER)