Page 1 of 1
How to trigger a page down key ?
Posted: Thu Apr 12, 2018 10:05 am
by chs
Hi everyone,
I have a rich display program with a grid and a textbox in each grid row. In the "Onkeydown Event" of the textbox, I would like to trigger a page down key when the cursor focus is in the textbox of the last visible row and the enter key is pressed.
Page down displays the next set of rows (or subfile page) and places the cursor in the first textbox (row) which is exactly what I want.
To find out in which textbox/row the cursor is works and to check whether the enter key is pressed and to prevent the enter key works as well. But how can I trigger the page down key now ?
Is it possible to trigger (or send) a page down or another key with a rich program ? And if so, how ?
I have tried to use pressKey("PageDown") but it didn't work resp. it triggered enter instead. As far as I have read, pressKey only works with Genie.
Is there an alternative to pressKey for rich programs ?
Page Down is key 34.
Thank you very much for your help in advance.
Christoph
Re: How to trigger a page down key ?
Posted: Thu Apr 12, 2018 10:09 am
by chs
My grid looks like this when executed:
Re: How to trigger a page down key ?
Posted: Thu Apr 12, 2018 10:23 am
by Emily
Hi Christoph,
The pressKey() API should work for both Genie and for Rich Displays. This is stated in the documentation page we have for the API:
http://www.profoundlogic.com/docs/pages ... Id=4849987. Notice that "PageDown" is listed as a valid value for pressKey() when using this with a Rich Display file. So, what you're trying to accomplish should work for you. I was able to set up a quick test using pressKey("PageDown"); and it seemed to page my grid as expected. I suggest checking the code that you are using to make sure there aren't any errors that would prevent this from working properly.
If you continue to have problems with this, please let us know and we'll be happy to assist you further.
Thanks!
Re: How to trigger a page down key ?
Posted: Fri Apr 13, 2018 4:41 am
by chs
Hi Emily,
Thank you for your answer.
I tried to use PressKey again, but it didn't work unfortunately. When I press the Page Down key it works (the cursor is in the first textbox of the second page), but when I use the PressKey command, it doesn't (the cursor is in the first textbox of the first page instead of the second page).
I have noticed, that for some reason the PressKey causes the program to go back to my RPG program which is not something I want. In my RPG program follows an Exfmt.
Here is my code in the onkeydown event of the textbox:
Code: Select all
if (js_StopEnterKeyEvent(event)) {
var row2 = row + 1;
var textzeile = getObj("TXT_info" + '.' + row2);
if(textzeile !== null) {
textzeile.focus();
}
if(textzeile === null) {
PressKey("PageDown");
}
}
The code does the following: When enter is pressed, it prevents the enter key and puts the cursor into the next line (textbox) which works. When the cursor is on the last line of the page, textzeile is null. In this case, I would like to send PressKey("PageDown").
The js_StopEnterKeyEvent(event) looks like this:
Code: Select all
function js_StopEnterKeyEvent( KeyEvent ) {
var IsStoped = false;
if (KeyEvent != null) {
// Welche Taste wurde gedrückt
var key = KeyEvent.keyCode;
// Enter abfangen
if (key == 13) {
// Enter-Event stoppen
preventEvent(KeyEvent);
IsStoped = true;
}
}
return IsStoped;
}
Thank you for your help in advance.
Christoph
Re: How to trigger a page down key ?
Posted: Fri Apr 13, 2018 4:53 am
by Scott Klement
Christoph,
The pressKey() API is meant to send a key that would submit a 5250 screen back to the server. It does not simulate a keyboard keypress, but instead always sends control back to the IBM i, and tells the IBM i that the screen was submitted with the given key.
That it why it can only be used with keys that nomally would submit a 5250 screen (F-keys, Enter, PageUp, PageDown, etc) and not with regular letters, numbers, etc. Because it is only the keys that trigger 5250 screens to go back to the server.
If your goal is to scroll a grid, use the grid's scrollToRow() API documented here:
http://www.profoundlogic.com/docs/pages ... d=15728644
Re: How to trigger a page down key ?
Posted: Fri Apr 13, 2018 7:03 am
by chs
Scott,
Thank you for your answer.
The scrollToRow() API scrolls to the second page with the first row of the second page on top (which is correct) but the cursor is not in the textbox of the first row of the second page.
This means: The user loses the focus of the cursor and cannot continue to press enter and jump to the next row and then to the next row. The focus is on the whole window and with another enter, control goes back to the rpg program and the user is back on the first page of the grid.
After the scrollToRow, I tried to set the cursor into the textbox of the first row of the second page, but unfortunately I doesn't work after scrollToRow.
Do you know why ?
Do you know how I can set the cursor after scrollToRow ?
Page down jumps to the second page and sets the cursor into the textbox of the first row which is exactly what I would like to achieve.
Thank you for your answer in advance.
Christoph
Re: How to trigger a page down key ?
Posted: Fri Apr 13, 2018 10:48 am
by Scott Klement
You may have to use focus() with a timeout to give scrollToRow() time to finish.