This is my code snippet,
reg = selectRegion("Selected a region")
reg.keyDown(KEY_CTRL)
reg.keyUp()
My objective is to select some lines, as we do it by pressing CTRL and then scrolling down, but it throws
java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Invalid key code
It's obvious that I have done something wrong, Could any one help me out with this??
The documentation on special keys says to use CTRL with keyDown(). KEY_CTRL is used with type() or other cases where you want to add the modifier key as a mask. (And that's actually deprecated and should be KeyModifier.CTRL now, instead.)
For example:
reg.keyDown(CTRL)
... some code that scrolls ...
reg.keyUp(CTRL)
Or to press the "down" key twice while holding control:
reg.type(Key.DOWN + Key.DOWN, KeyModifier.CTRL);
(As a side-note, it's generally shift that's used as the modifier key for creating a selection and not control.)
Related
I came across this solution to my initial problem, which was to simulate an ENTER or RETURN key press using Selenium WebDriver.
However, in my code, I strictly want to use only one of the two WebElement.sendKeys(Keys.ENTER); vs WebElement.sendKeys(Keys.RETURN);.
What is the best practice when doing the same, since there seems to be divided opinion about using enter or return, since both work MOST of the time? In what scenarios would one or the other not work, and is there one which would ALWAYS work?
As a performancewise I do not get any change on both of these,
But yes I know one difference on them
Keys.Enter is used to enter key on the number pad
while
Keys.Return is used to one next to the letters
Generally I have preferred Keys.Enteras sometimes in some browser Keys.Return is not worked for me
Let us analyze Keys.ENTER and Keys.RETURN in details.
Keys.ENTER and Keys.RETURN both are from org.openqa.selenium.Keys, which extends java.lang.Enum<Keys> and implements java.lang.CharSequence
Enum Keys :
Enum Keys is the representations of pressable keys that aren't text. These are stored in the Unicode PUA (Private Use Area) code points, 0xE000-0xF8FF.
Key Codes :
The special keys codes for them are as follows :
RETURN = u'\ue006'
ENTER = u'\ue007'
The implementation of all the Enum Keys are handled the same way.
Hence there is No Functional or Operational difference while working with either sendKeys(Keys.ENTER); or WebElement.sendKeys(Keys.RETURN); through Selenium.
Enter Key and Return Key :
On computer keyboards, the Enter (or the Return on Mac OSX) in most cases causes a command line, window form, or dialog box to operate its default function. This is typically to finish an "entry" and begin the desired process, and is usually an alternative to pressing an OK button.
The Return is often also referred as the Enter and they usually perform identical functions; however in some particular applications (mainly page layout) Return operates specifically like the Carriage Return key from which it originates. In contrast, the Enter is commonly labelled with its name in plain text on generic PC keyboards.
Wiki References : Enter Key Carriage Return
As yourself, I failed to find a good explanation to this question online so I tested it myself using this Keyboard Events tester.
driver.get("https://dvcs.w3.org/hg/d4e/raw-file/tip/key-event-test.html");
WebElement textArea = driver.findElement(By.id("input"));
textArea.sendKeys(Keys.ENTER);
textArea.sendKeys(Keys.RETURN);
As a result I've got this output (this is Keys.ENTER followed by Keys.RETURN):
So it seems like there is no difference between these two options.
Just learning spacemaces and wondering how to best interact with auto completion behavior...
So, below my cursor is the pipe |, if i type def for instance (elixir) then I get a nice
def | do
end
So I type my function name and a paren and now I have
def my_fun(arg|) do
end
I want now to stay in edit mode and press some key combo that says I am done with the parens so move me past the close paren, and then press it again since I am done with the def header so move me to the body.
Maybe this is a minor mode? Not sure what the edit mode key mappings are generally.
Thanks for any help.
Not sure I understand what is responsible for each behavior but I did learn that yasnippets is what I want for the behavior I described, and then M-/ expand a snippet where TAB moves me through the template cursor positions.
The checkbox "Smart Characters" in "Code Completion" section of Settings Browser does (at least) two things:
1) It doubles some characters when typed: ', ", (, [, {
2) It enables that I can select a piece of code, press ( (i.e. Shift+9), and the selected code becomes surrounded by parentheses: (). I also can remove parentheses by pressing ( again. I also can do this with [] by pressing [ and with {} by pressing {, i.e. Shift+[.
I do not like the first of these things so I want to disable it, but I like the second thing and want to keep it. How can I achieve this? Turning off the checkbox will disable both.
P.S. I know that when the checkbox is off, adding/removing parentheses works by Cmd+Shift+9 (which is less convenient than Shift+9) and that Cmd+[ works for [], although I do not know any working shortcut for adding/removing {} when the checkbox is off.
The setting is called "Smart Characters", which should give you a clue as to where to look. Open a Finder, type in smartCharacters, and hit Enter. You should see some partial matches as well as an exact match for NECController and NECPreferences class (and the former just calls the latter). If you investigate the classes involved a bit, you'll see that smartCharacters stores a boolean, and that smartCharactersMapping returns a dictionary mapping some characters to their "counterparts", i.e. $[ to $] and so on. Now look at senders of smartCharactersMapping, and you'll see where it's being called from.
The caller you're most likely interested in would be NECController>>smartCharacterWithEvent. So put a breakpoint in that very ugly method to see what it does. You don't care about the first two cases (the editor having a selection and there not being a smart mapping), since you want to prevent the second matching character from being inserted. So the interesting bit for you is this bit:
self newSmartCharacterInsertionStringForLeft: char right: opposite
The method only has one implementor and that one sender, so it should be safe to comment out the original method and just return the "left" character, i.e.:
newSmartCharacterInsertionStringForLeft: left right: right
^String with: left
In other words, instead of creating a string with the left and right characters, and possibly spaces between them, just return a new string with the single character you typed. Might not be the most elegant way of solving this, but it should work, and should show you how to solve similar problems in the future.
(Ideally, you'll find a better solution, post it here as an alternate answer, and contribute it to the Pharo codebase - Pharo is open source, after all.)
Is there any intellij idea shortcut to select a token in a statement?
For example, consider this:
cell.setCellValue((profileInfo.get("startTimeOfCrawl")!=null)?profileInfo.get("startTimeOfCrawl"):"");
Currently, if my cursor is on the first character of the above statement(i.e. at beginning of c of cell, if I have to select profileInfo, then I will have to use my mouse and double click on profileInfo to select that.
Another workaround I found was to use arrow keys to get cursor to profileInfo
Then use ctrl+shift+right-arrow keys to select till the end(i.e. till o) of profileInfo
This is good when my cursor is placed at beginning of profileInfo(or even end in which case we can use left-arrow key).
But if my cursor is placed somewhere in between of profileInfo then I will have to use ctrl+right (or ctrl+left) to get the cursor to either beginning or end of this token. Then I Will have to use ctrl+shift+right-arrow (or left-arrow as the case may be).
(Switching from keyboard to mouse breaks the continuity, hence looking for keyboard shortcuts.)
Is there a better shortcut to do above in 1 step?
PS: Solution to above will be very useful when making string replacements.
Use Edit | Extend Selection (Ctrl-W in the default keymaps, Alt-Up in the Mac OS 10.5+ keymap). You can press it multiple times to extend the selection to larger enclosing syntax constructs.
I can't think of a 1-step process of doing this but try using the alt to traverse via arrow keys, it will traverse it per "word" instead of per character.
You can also use alt+shift+ arrow keys to select per word.
I'm trying to automate keyboard typing with UI Automation.
target.frontMostApp().keyboard().typeString("INTERCOM")
But i will get this error after first 'I' is typed
target.frontMostApp().keyboard() failed to locate key 'N'
Script threw an uncaught JavaScript error: target.frontMostApp().keyboard() failed to locate key 'N'
I have a localized swedish keyboard.
Anyone know if this a bug or something I've missed?
This might help:
var vKeyboard = target.frontMostApp().keyboard();
vKeyboard.setInterKeyDelay(0.1);
vKeyboard.typeString("INTERCOM");
By default this delay is set with 0.03 seconds. This is not enough for your application to update the keys on your keyboard. Increasing this timeout between determining keys for typeString keyboard method will help you. There is no description for setInterKeyDelay on UIAKeyboard reference page but this method is available for UIAKeyboard.
Also I'm not sure about other languages. I do not know if typeString allows to type on other languages but this 100% works for English keyboard for iOS 5.x.
try{
target.delay(1);
target.frontMostApp().mainWindow().textFields()[0].tap();
target.delay(1);
target.frontMostApp().mainWindow().textFields()[0].setValue("INTERCOM");
}
catch(err){
target.delay(1);
target.frontMostApp().mainWindow().scrollViews()[0].textFields()[0].tap();
target.delay(1);
target.frontMostApp().mainWindow().scrollViews()[0].textFields()[0].setValue("INTERCOM");
}
I've had this problem as well and I believe it's a case of the string being typed too quickly.
It seems that the names of the key,change depending on the status of the shift button.If shift is enabled then the key is called 'N',if shift is not enabled then it's 'n'.You'll notice as a string is being typed,that the shift button is tapped before an uppercase letter is typed.Your test is attempting to press the 'N' key before the 'Shift' button has been pressed.It doesn't affect the first letter of your sentence because the keyboard has shift enabled for the first letter.
This also affects typing a lowercase character after an uppercase character:the lowercase character may be typed whilst the shift button is in the process of being unpressed.
I use a workaround of typing each letter of the string with separate typeString() methods.
for (i = 0; i < title.length; i++)
{
var strChar = title.charAt(i);
target.frontMostApp().keyboard().typeString(strChar);
}
The downside to this is that it takes a lot longer to type the full string.
You may also want to look at the following link which provides a similar solution but uses the app.keyboard().keys().tap() method for each character of the string instead of the typeString() method.
http://jojitsoriano.wordpress.com/2011/06/27/ios-ui-automation-typing-a-string-in-a-uiatextfield/