Hi folks,
Is there a way to know which arrow key the user pushed in the screen?
In other words, we have a right arrow to advance to the next question, and a left arrow to retrun to the previous field.
How do we know which one is pushed?
Best
Ari
How to identify the usage of the arrow keys
-
- Posts: 227
- Joined: November 21st, 2022, 4:41 pm
Re: How to identify the usage of the arrow keys
Hello,
Pushing the right arrow to advance is the same as advancing with the Enter key on Windows, or advancing through logic on Android. When advancing it will execute the postproc of the current field and then the preproc of the next field as normal. If pushing the left button it will go back to the previous field, executing the onfocus but NOT the preproc for that previous field. You can set variables in the preproc to tell whether a question was advanced to normally or not. Does this help answer your question?
Hope this helps,
Justin
Pushing the right arrow to advance is the same as advancing with the Enter key on Windows, or advancing through logic on Android. When advancing it will execute the postproc of the current field and then the preproc of the next field as normal. If pushing the left button it will go back to the previous field, executing the onfocus but NOT the preproc for that previous field. You can set variables in the preproc to tell whether a question was advanced to normally or not. Does this help answer your question?
Hope this helps,
Justin
-
- Posts: 1851
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: How to identify the usage of the arrow keys
On Windows, you can also keep track of all keys:
numeric lastKeystroke;
function OnKey(keystroke)
lastKeystroke = keystroke;
exit keystroke;
end;
Then you can look at lastKeystroke to determine if the last pressed key was an Enter, left arrow, tab, right arrow, etc.function OnKey(keystroke)
lastKeystroke = keystroke;
exit keystroke;
end;
Re: How to identify the usage of the arrow keys
Some questions about Greg's answer:
1. the OnKey(keystroke) works only on windows, not in android?
2. which are the codes for left key and right key?
And from Justin:
when you say "If pushing the left button it will go back to the previous field", what it the meaning of "previous" field?
. the field before in teh field list?
. the field where we used a skip to skip the the present field?
. the field where we used a move to move to the present field?
And last:
In android, is there a way to prevent the left field to be pushed? I know we can prevent to show both arrows, but I want to eliminate ONLY the left arrow.
Best
Ari
1. the OnKey(keystroke) works only on windows, not in android?
2. which are the codes for left key and right key?
And from Justin:
when you say "If pushing the left button it will go back to the previous field", what it the meaning of "previous" field?
. the field before in teh field list?
. the field where we used a skip to skip the the present field?
. the field where we used a move to move to the present field?
And last:
In android, is there a way to prevent the left field to be pushed? I know we can prevent to show both arrows, but I want to eliminate ONLY the left arrow.
Best
Ari
Best
Ari
Ari
Re: How to identify the usage of the arrow keys
What I would like to have is a check to know if I got here using the left key, like:
if lastkey(leftkey) then
...
endif;
if lastkey(leftkey) then
...
endif;
Best
Ari
Ari
-
- Posts: 6
- Joined: April 9th, 2024, 3:45 am
- Location: India
Re: How to identify the usage of the arrow keys
Hey hi, you can use JavaScript event listener to detect keydown events. By checking the event.keyCode property, you can determine whether the user pressed the left or right arrow key. Then, you can execute the appropriate action in your application.
ex
ex
Code: Select all
document.addEventListener("keydown", function(event) {
switch(event.keyCode) {
case 37:
// Left arrow key pressed
// Perform action to return to previous field
break;
case 39:
// Right arrow key pressed
// Perform action to advance to the next question
break;
// Add cases for other arrow keys if needed
}
});
-
- Posts: 1851
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: How to identify the usage of the arrow keys
Regarding the OnKey function, which does indeed work only on Windows, you can use the OnKey Character Map to determine the keystrokes for left, right, etc.:
https://www.csprousers.org/help/CSPro/o ... r_map.html
https://www.csprousers.org/help/CSPro/o ... r_map.html