24

This feels like it should be pretty easy but I can't find documentation on how to do this:

I just want Sikuli to type Ctrl+C to copy text to the clipboard.

type(KEY_CTRL+'c') doesn't work and neither does type(KEY_CTRL,'c').

Any suggestions?

10 Answers 10

27

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)
2
  • 2
    That was it, (KEY_CTRL,'c') doesn't work but ('c', KEY_CTRL) does, go figure!
    – Dave S
    Commented Jun 15, 2011 at 0:24
  • 4
    Deprecated since version X1.0-rc3. See the answer by @spearson.
    – willkil
    Commented Dec 21, 2012 at 21:20
19

The following works in 0.9 and newer versions of

type('x', KeyModifier.CTRL)
1
  • 3
    Please note that this is case sensitive! 'x' and 'c' work, but 'X' and 'C' do not! Commented Aug 19, 2015 at 15:02
7

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)

2
  • This works but takes 3 lines when just 1 line is enough type('x', KeyModifier.CTRL) Commented Aug 19, 2015 at 15:09
  • its useful for when you want to have one part of your program handle pushing down modifiers and another part going about its merry way, un knowing of whether the button is pressed or not currently
    – Belfordz
    Commented Nov 13, 2015 at 21:03
5

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

2

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.

1

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

0

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

2
  • Num Lock doesn't make any difference for me. Did you see this issue on a particular platform? Commented Aug 19, 2015 at 15:10
  • 1
    @JonathanBenn, I was using Windows 7 Home Premium, Java 7 (update 65), and Sikuli 1.0.1.
    – autoKarma
    Commented Aug 26, 2015 at 13:35
0

You can try next code:

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

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);
-1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.