How to send “Ctrl + c” in Sikuli?

此生再无相见时 提交于 2019-12-03 09:21:03

问题


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?


回答1:


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:


The following works in 0.9 and newer versions of sikuli

type('x', KeyModifier.CTRL)



回答3:


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)




回答4:


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

  • http://doc.sikuli.org/region.html#Region.type
  • http://doc.sikuli.org/keys.html#key-constants



回答5:


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




回答6:


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.




回答7:


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




回答8:


You can try next code:

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



回答9:


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



回答10:


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.



来源:https://stackoverflow.com/questions/6337629/how-to-send-ctrl-c-in-sikuli

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