event.which value 'incorrect' - ascii

I get the "incorrect" value for event.which in chrome. for example:
$(document).keypress(function (e) {
alert(String.fromCharCode(e.which));
alert(e.which);
});
this code produces two alerts when I press the numpad '+' key, first says k, second says 107.
I want the first one to say + and the second, well the second doesn't matter too much, all I care about is getting the + symbol when typing the + key. Same for all mathematical operators, I am writing a calculator and need those symbols correct for the input elements. How do I do it?
---- WORKING ----
I must have done something wrong before, now it works great...

Try using .keydown instead , i had few issues earlier with keypress behaviour in chrome which got resolved when I used keydown

Related

How to resolve missing characters bug in Cypress type() command?

I have a problem regarding typing into the search field of the select2 element. In some tests random character is missing while executing type() command. I tried to wait() before start typing and type with timeout after each character but nothing helped. So the bypass implemented by me is putting the string into the field as a whole instead of typing it char by char:
this.getSelect2Input().invoke('val', str).trigger('change')
but in this case the test does not understand that the string has been input and continue to wait for input. So the solution was to add a space at the end of the string:
this.getSelect2Input().invoke('val', str).trigger('change').type(' ');
It works but not for the all tests as in some cases the space is treated as additional character and the string can not be found. For this case I can't found nothing else then typing a space and deleting it (I know that this is not good solution, but what can I do?):
this.getSelect2Input().invoke('val', str).trigger('change').type(' {backspace}');
But now this is not working as well as in some cases the space is printed but is not deleted. Can anybody advice how to initiate select2 search after setting the value of the field? type({'enter'}) does not work as well.
If this.getSelect2Input() translates into something cy.get('locator'), you can add a delay with type() and also add .should to make sure the intended value that you're typing is typed correctly.
// Delay each keypress by 0.1 sec
this.getSelect2Input().type('slow.typing#email.com', {
delay: 100
}).should('have.value', 'slow.typing#email.com')
Or, You can also add a timeout:
// Add a timeout of 10 seconds
this.getSelect2Input().type('slow.typing#email.com', {
timeout: 10000
}).should('have.value', 'slow.typing#email.com')

Xcode XCUITest - extra characters entered into searchField when using typeText

I have a test in Xcode (XCUITests) that uses typeText to enter a string into a searchField. For our test, we do 2 taps into the searchField first. Then, we do:
searchField.typeText(ourStringHere + "\n")
When this line runs, it types the first character 2 extra times. So, if we pass in "tree", it will type "tttree". This obviously causes our tests to fail.
On this screen in our app that we are testing, we have actions occur based on matching as you type. So, after the first character is typed, some results are shown. I believe this is causing a timeout issue.
Then Xcode is trying to type the whole word again. I believe this also happens twice. On the third attempt, the screen has settled down with it's background actions and the word it then successfully typed.
Ifs there was some way to override typeText() to delete anything it had previously tried, that would be helpful. Also, adding some pauses in between characters as they are typed would help. We could then have the test wait for the background actions to show all of the results and then type the next letter.
Other than this, I don't know how to fix this.
Based on your preconditions I think you should paste text instead of typing (but it is a little unsafe if you run your tests in parallel)
let pasteMenuItem = app.menuItems.firstMatch
UIPasteboard.general.string = "Preparing Pasteboard"
searchField.tap()
searchField.tap()
_ = pasteMenuItem.waitForExistence(timeout: 5)
UIPasteboard.general.string = ourStringHere + "\n"
pasteMenuItem.tap()
Also, check out comments here typeText() is typing inconsistent characters for a slow typing.

how to break a line in RStudio

New to R, and have trouble with RStudio but not with R GUI when typing a long code.
R GUI allows me to break the line of code when pressing Enter by adding +
e.g.
>rolldice <- function (){
+ dice <-1:6
+ rolldice <- sample (x=dice, size=2)
+ sum (rolldice)
}
However, in RStudio, it autocompletes part of the code when I try something like below
>rolldice <-function (){}
I tried to add additional codes within the bracket but somehow could not break the line by Enter. Enter would end the function, not adding additional lines with +. Thus I am stuck with either
(when not pressing Enter)
>rolldice <- function (){dice<1:6 rolldice <- sample(x=dice, size=2) sum(rolldice)}
which is considered an error code by RStudio
or
when pressing Enter to attempt to create a line breaker, which gives me the following
>rolldice <- function (){}
>
Surprisingly googling this (e.g. RStudio line breaker) did not yield any solution. One suggestion was to add n , but I have no clue what n is (obviously I tried the alphabet, but it was wrong).
I know I must have missed some piece of relevant info on the internet or in a book, since this is one of the most rudimentary issues in learning a new language.
Any help?

QTP : Sendkey method with the combination of Ctrl key doesn't work

I wanted to use the short cut key in VBA scripting instead of clicking on the objects.
So I used this code below ( ^F6 ) to press "ctrl+F6". But it didn't work and displays a syntax error.
SAPGuiSession("Session").SAPGuiWindow("Aufteiler anlegen : Einstieg").SendKey ^F6
However, +F6 for "SHIFT + F6" worked perfectly. Could anyone figure it out?
QTP doesn't translate ^ to control, instead it uses a special constant micCtrl.
Something like this might work (untested)
With SAPGuiSession("Session").SAPGuiWindow("Aufteiler anlegen : Einstieg")
.SendKey micCtrlDown
.SendKey micF6
.SendKey micCtrlUp
End With

Visual studio CTRL+SHIFT+T transpose - what does it do?

I wrote some code and tried the Ctrl + T to check transpose feature in visual studio.
Just to check if CTRL + Shift + T does the reverse for this Transpose... I tried pressing Ctrl + Shift + T.
and it just messed up everything...
Can anyone tell me what exactly this Ctrl + Shift + T does (especially with a block) ?
For instance:
public string returnDateTimeToMyformat(DateTime dt)
{
dt = dt.AddYears(-1);
return dt.ToString("yyyy MM dd HH mm ss");
}
To:
string returnDateTimeToMyformat publicdtDateTime (dt
{
dt = )1AddYears(-.return;
dt ).ToString("yyyy MM dd HH mm ss");
}
(I started with my cursor right after 'public')
Since CTRL-T swaps the two characters on either side of the cursor, the opposite of it is ...
wait for it ...
CTRL-T
:-)
CTRLSHIFTT transposes the two words after the cursor.
What it's doing to your block seems rather bizarre. It appears to doing it to multiple parts of each line. My only advice would be (as the doctor said to the patient who complained it hurts when banging their head against a wall): Don't do that.
As others have pointed out, the two words following the cursor are transposed, and the cursor is placed after the words that have been transposed. However, Visual Studio 2010 at least appears to ignore commas and other punctuation when considering "words." One utility of this, then, is that you can reorder something like an enum. For instance,
typedef enum myEnum
{
ThingOne,
ThingThree,
ThingTwo
};
Put the cursor somewhere near ThingThree and press CtrlShiftT to get:
typedef enum myEnum
{
ThingOne,
ThingTwo,
ThingThree
};
This could be a good thing if you decide that a different order for your enums is better. You can also use this to help idiot-proof comparisons and/or quickly and easily format them to a better coding standard.
if ( ptr == NULL ) { /* stuff */ }
is considered bad (never mind that having an "if" on its own line is also bad) since you could easily write (or read) "ptr = NULL" by accident. You're better off with
if ( NULL == ptr ) { /* stuff */ }
So, if you did it wrong the first time, just select the offending expression and...CtrlShiftT to the rescue!
...Yeah, okay, so this thing isn't that useful.
Edit: Hmm, I should add that the behavior is a little weirder when your cursor is placed immediately before a punctuation symbol (such as a left-parenthesis), hence the weird result you got when you repeatedly hit CtrlShiftT on your code snippet. It seems to just swap any whitespace-terminated string after the cursor with the next alphanumeric "word," skipping over any punctuation symbols in between. The result is often difficult to read, though, so I'm not going to claim that's the exact pattern.
According to this website:
Transposes the two words that follow
the cursor. (For example, |End Sub
would be changed to read Sub End|.)
The only question that remains is probably: WHY??
Well it might become handy when you have a block of code lines where variables are assigned values. (For example Load/Save) In the opposite function, you want to do the opposite assignment, maybe this shortcut can be used in such a situation...
With this Visual Studio Document Reopen cool extension CTRL+SHIFT+T you can reopen the last closed document(s). It works like in Web browsers.

Resources