What is the JavaFX KeyCode for the character: ` - javafx

What is the JavaFX KeyCode for the character: ` ?
I have tried searching KeyCode and the only candidate I see is "BACK_QUOTE", but that seems to correspond to À according to this (probably an encoding issue).
System.out.println ( KeyCode.BACK_QUOTE.getChar() );
In either case, I don't think that represents ` and I can't find any other candidates.
KeyCode.getKeyCode( "`" )
returns null, so that's wierd.

When listening for KeyEvent.KEY_PRESSED events it gives me KeyCode.BACK_QUOTE as the code when I press the ` key.
// Prints BACK_QUOTE
primaryStage.addEventFilter(KeyEvent.KEY_PRESSED, event -> System.out.println(event.getCode()));
If I listen to KeyEvent.KEY_TYPED events the character is ` when I type `.
// Prints `
primaryStage.addEventFilter(KeyEvent.KEY_TYPED, event -> System.out.println(event.getCharacter()));
However, I also get À from KeyCode.BACK_QUOTE.getChar(). I'm not sure why there's an inconsistency, but it appears the KeyCode for ` is BACK_QUOTE.

Related

Why can't Qt distinguish the hyphen and the minus key?

I'm reviewing some part of a project written with Qt:
void Editor::keyPressEvent(QKeyEvent* event)
{
int key = event->key();
switch (key) {
case Qt::Key_Tab:
...
I've put a breakpoint at int key = event->key().
Now, I've notice that pressing the minus "-" on the keypad shows me in debug:
Pressed 'Minus' (key:45 vKey:65453)
Qt::Key_Minus (0x002d)
Then, pressing "-" (the hyphen on the hyphen/underscore key gives me:
Pressed 'Minus' (key:45 vKey:45)"
Qt::Key_Minus (0x002d)
1439241440
So they are definitely detected as different (judging from this "vKey" number) but the event is the same: "Key_Minus".
Why can't I get the "Key_hyphen" event? How could I solve this (maybe using this "vKey" number?
Try
event->nativeVirtualKey();
and
event->nativeScanCode();

Inputbox and cases, cancel or closing the window

I'm new to autoit, and I'm wondering how to deal with some things. The code is simply this line :
$input = InputBox("game : +/-", "Write a number:")
If I write a number in the section, the program goes normaly.
If I click the cancel button, an error is thrown and so I dealt with it with :
If (#error = 1) Then
$End = True
Is what I ve done okay?
And :
Could you please explain what is going on here and what exactly is happening if I enter no value or if I press cancel?
If I close the windows, what happens ? I'd like the program to end.
Thank you very much ! Sorry if my question is easy or useless, I'll help me a lot
with a couple of ternary ops you can see that the cancel button sets the error flag and it does =1 or ==1 or =True (because True evaluates to 1)
$input = InputBox("game : +/-", "Write a number:")
$result = (#error == 1) ? 'cancel was pressed' : $input
msgbox(0, '' , $result = '' ? 'empty string' : $input)
When you call the InputBox function values are returned to indicate the result of the process these are:
Success: the string that was entered.
Failure: "" (empty string) and sets the #error flag to non-zero.
#error: 1 = The Cancel button was pushed. 2 = The Timeout time was
reached. 3 = The InputBox failed to open. This is usually caused by
bad arguments. 4 = The InputBox cannot be displayed on any monitor. 5
= Invalid parameters width without height or left without top.
So essentially that means that if it returns a non-empty string, the "success" case, you don't have to worry about #error. If any non-zero value is returned, the value of #error will indicate what has happened. So if in the case of an error you just want to return, you should use this if statement:
If (#error <> 0) Then
$End = True
This works because we know if #error == 0 then the input box has been successful and a value has been returned, otherwise we know it's thrown one of the errors listed above. I would anticipate that closing the window has the same effect as pressing cancel, i.e. #error == 1 but I haven't checked.
Further to this, if you wanted to you could switch on the value of #error and use that to give the user an error message along the lines of "please enter a value" or "command timed out" but that seems more than is required in this instance.
Here's the relevant documentation: https://www.autoitscript.com/autoit3/docs/functions/InputBox.htm
Good luck!

"Down arrow" moves cursor to end of line - how to turn it off

In IPython Notebook / Jupyter, arrow up/down keystrokes within a cell are handled by CodeMirror (as far as I can tell). I use these actions a lot (re-bound to control-p / control-n) to move between cells; but at the end of every cell, the cursor moves to end of line first before jumping to the next cell. This is counter-intuitive and, to me, rather distracting.
Is there any way to configure CodeMirror to make this move down to be just that - a move down?
Thanks!
The moving-to-next-cell behavior is defined by IPython wrapper code, which probably checks whether the cursor is at the end of the current cell, and overrides the default CodeMirror behavior in that case. You'll have to find that handler and somehow replace it with one that checks whether the cursor is on the last line. (I don't know much about IPython, only about CodeMirror, so I can't point you at the proper way to find and override the relevant code. They might have bound the Down key, or they might have overridden the goLineDown command.)
Knowing that I wasn't alone in wanting to skip the "going to end of line" behavior when going down from the last line of a code cell, I investigated that behavior and found out that:
it's CodeMirror that goes to the end of line when you type down in the last line of a code cell (file: codemirror.js ; "methods": findPosV and moveV)
and it's IPython that decides what to do with the "down" event after it has been handled by CodeMirror (file: cell.js ; class: Cell ; method: handle_codemirror_keyevent) ; looking at the code, I saw that IPython ignores the event when not at the last character of the last line.
This essentially confirms Marijin's answer.
The primary goal being to jump to the next cell, I think there's no need to prevent CodeMirror from going to the end of that line. The point is to force IPython to handle the event anyway.
My solution was to change the code from Cell.prototype.handle_codemirror_keyevent to this:
Cell.prototype.handle_codemirror_keyevent = function (editor, event) {
var shortcuts = this.keyboard_manager.edit_shortcuts;
var cur = editor.getCursor();
if((cur.line !== 0) && event.keyCode === 38){
// going up, but not from the first line
// don't do anything more with the event
event._ipkmIgnore = true;
}
var nLastLine = editor.lastLine();
if ((event.keyCode === 40) &&
((cur.line !== nLastLine))
) {
// going down, but not from the last line
// don't do anything more with the event
event._ipkmIgnore = true;
}
// if this is an edit_shortcuts shortcut, the global keyboard/shortcut
// manager will handle it
if (shortcuts.handles(event)) {
return true;
}
return false;
};
This code provides the desired behavior for the "down-arrow" key (almost: the cursor still goes to the end of the line, except that we don't see it, as we're already in another cell at that point), and also handles the "up-arrow" key similarly.
To modify the handle_codemirror_keyevent prototype, you have two possibilities:
You edit the cell.js file and change the code of the prototype to the code I gave above. The file is in <python>/Lib/site-packages/IPython/html/static/notebook/js or something similar depending on you distro
Much better, after the page is loaded, you change that prototype dynamically by doing this:
IPython.Cell.prototype.handle_codemirror_keyevent = function (editor, event) {
<same code as above>
};
You can do that in your custom.js for example, or create an extension to do it (that's what I did).

Codeception pressKey ENTER does not work

I am not familiar with codeception. I am trying to insert a text in an input field and press the ENTER button.
$I->fillField('#token-input-yw1', 'Some string');
$I->pressKey('#token-input-yw1', 13);
The text is entered but the enter key is not pressed. Any ideas?
If anyone still have problem with pressing Enter key, here is a solution: (if you are using Webdriver with Selenium)
$I->pressKey('#input',WebDriverKeys::ENTER);
Hopefully someone will find this useful.
See http://codeception.com/docs/modules/WebDriver#pressKey
pressKey
Presses the given key on the given element. To specify a character and modifier (e.g. ctrl, alt, shift, meta), pass an array for $char with the modifier as the first element and the character as the second. For special keys use key constants from WebDriverKeys class.
<?php
// <input id="page" value="old" />
$I->pressKey('#page','a'); // => olda
$I->pressKey('#page',array('ctrl','a'),'new'); //=> new
$I->pressKey('#page',array('shift','111'),'1','x'); //=> old!!!1x
$I->pressKey('descendant-or-self::*[ * `id='page']','u');` //=> oldu
$I->pressKey('#name', array('ctrl', 'a'), \Facebook\WebDriver\WebDriverKeys::DELETE); //=>''
?>
param $element
param $char Can be char or array with modifier. You can provide
several chars.
throws \Codeception\Exception\ElementNotFound
Please note, that you may need to add \ or \Facebook\WebDriver\ before WebDriverKeys:
\Facebook\WebDriver\WebDriverKeys::ENTER
I had the same problem. I pressed enter this way:
$I->executeJS('event.keyCode=13');
$I->fillField('input onkeypress=','13');
$I->pressKey('photo_link', '13');
But it didn't work.
I fixed it with the next code:
$I->executeJS("$('input#photo_link').trigger(jQuery.Event('keypress', {keyCode: 13}));");
It equals enter key, try it.

UDK "Error, Unrecognized member 'OpenMenu' in class 'GameUISceneClient'"

Upon compiling, I am getting the following error:
C:\UDK\UDK-2010-03\Development\Src\FixIt\Classes\ZInteraction.uc(41) : Error, Unrecognized member 'OpenMenu' in class 'GameUISceneClient'
Line 41 is the following:
GetSceneClient().OpenMenu("ZInterface.ZNLGWindow");
But when I search for OpenMenu, I find that it is indeed defined in GameUISceneClient.uc of the UDK:
Line 1507: exec function OpenMenu( string MenuPath, optional int PlayerIndex=INDEX_NONE )
It looks like I have everything correct. So what's wrong? Why can't it find the OpenMenu function?
From the wiki page on Legacy:Exec Function:
Exec Functions are functions that a player or user can execute by typing its name in the console. Basically, they provide a way to define new console commands in UnrealScript code.
Okay, so OpenMenu has been converted to a console command. Great. But still, how do I execute it in code? The page doesn't say!
More searching revealed this odd documentation page, which contains the answer:
Now then, there is also a function
within class Console called 'bool
ConsoleCommand(coerce string s)'. to
call your exec'd function,
'myFunction' from code, you type:
* bool isFunctionThere; //optional
isFunctionThere = ConsoleCommand("myFunction myArgument");
So, I replaced my line with the following:
GetSceneClient().ConsoleCommand("OpenMenu ZInterface.ZNLGWindow");
Now this causes another error which I covered in my other question+answer a few minutes ago. But that's it!
Not sure if this is your intent, but if you are trying to create a UIScene based on an Archetype that has been created in the UI Editor, you want to do something like this:
UIScene openedScene;
UIScene mySceneArchetype;
mySceneArchetype = UIScene'Package.Scene';
GameSceneClient = class'UIRoot'.static.GetSceneClient();
//Open the Scene
if( GameSceneClient != none && MySceneArchetype != none )
{
GameSceneClient.OpenScene(mySceneArchetype,LocalPlayer(PlayerOwner.Player), openedScene);
}

Resources