How to send “Ctrl + c” in Sikuli?

 ̄綄美尐妖づ 提交于 2019-12-03 02:28:41
Jompa234

Try using type("c",KEY_CTRL) instead.

I wrote a simple script which types a line in notepad, double clicks it to mark it and then ctrl+x ctrl+v it into the document again. Works great.

openApp("notepad.exe")

find("textfield.png" )
type("Some text")
doubleClick("theText.png")

type("x", KEY_CTRL)

click("theTextField.png" )
type("v",KEY_CTRL)
spearson

The following works in 0.9 and newer versions of

type('x', KeyModifier.CTRL)

Key objects are defined for pretty much all the modifier keys and num pad keys. Anyways, it should look something like this

keyDown(Key.CTRL)
type('c')
keyUp(Key.CTRL)

The usage of type() and the possible key names are documented here:

type('x', Key.CTRL) also works.

As others have mentioned, use the following:

type('c', Key.CTRL) # Copy command

One point worth mentioning - do not use upper-case characters, i.e.:

type('C', Key.CTRL) # Does not copy, avoid this

I haven't looked into the Sikuli source code, but my best guess is that it implicitly sends this as Shift+C, which results in a different command entirely.

Also, make sure that NUM_LOCK is off. If NUM_LOCK is on, it can make anything with KeyModifier.CTRL or KeyModifier.SHIFT misbehave.

You can try next code:

keyDown(Key.CTRL)
type("c")
keyUp(Key.CTRL)
user3363458

I had a requirement to automate a flash content. The following code worked for me. These were the following steps I ahd to perform as a part of the automation:

  1. Enter Username and Password
  2. Click on Login Button
  3. Click on the button which will navigate to the application

The challenge I faced was to focus on the Username and password which had no placeholders . Hence the focusing was difficult. So I used the CTRL keys to do this .

    Pattern appLogo = new Pattern("C:\\images\\appLogo.png");
    StringSelection userNameText = new StringSelection("username");              
   Toolkit.getDefaultToolkit().getSystemClipboard().setContents(userNameText, null);//Copy the text into the memory   
        Screen s = new Screen(); 
            s.find(appLogo);
            s.click(appLogo);
            s.type(Key.TAB);//I had to enter tab twice to focus on user name textbox
            s.type(Key.TAB);
            s.type("V",KeyModifier.CTRL);

            StringSelection password = new StringSelection("password");               
            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(password, null);
            s.type(Key.TAB);//I had to enter tab twice to focus on user name textbox
            s.type("V",KeyModifier.CTRL);

            Pattern loginButton =  new Pattern("C:\\images\\Login.png");
            s.find(loginButton);
            s.doubleClick(loginButton);

The scenario is like i need to press say key E in my keyboard after finishing the test how to add this in the script in Sikuli IDE.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!