Letters as Shortcut for Buttons
-
- Experienced User
- Posts: 122
- Joined: Tue May 22, 2012 6:45 am
- First Name: Dieter
- Last Name: Schröder
- Company Name: Ecclesia Holding GmbH
- State / Province: Outside Canada/USA
- Country: Germany
- Contact:
Letters as Shortcut for Buttons
Hello,
we have a tool, which shows a question in a window. The window has three buttons with the caption "Yes", "No" and "Cancel". For the cancel button we have defined the shortcut key F12. The users wish to have shortcut keys for the "yes" and "no" buttons too. So they would like to have a "Y" for the "yes button" and a "N" for the "no button".
Do you have any idea to implement this?
Dieter
we have a tool, which shows a question in a window. The window has three buttons with the caption "Yes", "No" and "Cancel". For the cancel button we have defined the shortcut key F12. The users wish to have shortcut keys for the "yes" and "no" buttons too. So they would like to have a "Y" for the "yes button" and a "N" for the "no button".
Do you have any idea to implement this?
Dieter
Last edited by dieter on Thu Jun 02, 2016 3:50 am, edited 1 time in total.
- Glenn
- Profound Logic Staff Member
- Posts: 124
- Joined: Mon Apr 14, 2014 4:08 pm
- First Name: Glenn
- Last Name: Hopwood
- Company Name: Profound Logic Software
- State / Province: Ohio
- Country: United States
- Contact:
Re: Letters a Shortcut for Buttons
Dieter,
I would put something like the code below in the 'onload' event of the window's record format. Replace the values in the pui.click() API calls with the ID's of your buttons.
Glenn
I would put something like the code below in the 'onload' event of the window's record format. Replace the values in the pui.click() API calls with the ID's of your buttons.
Code: Select all
document.addEventListener('keydown',
function(event) {
if(event.keyCode == 89) {
// 'Y' key pressed
pui.click("btnYes");
}
if(event.keyCode == 78) {
// 'N' key pressed
pui.click("btnNo");
}
}
);
-
- Experienced User
- Posts: 116
- Joined: Wed Sep 05, 2012 11:14 am
- First Name: Eric
- Last Name: Hill
- Company Name: Integrated Corporate Solutions
- Phone: 256-760-8239
- Address 1: 501 S Wood Avenue
- City: Florence
- State / Province: Alabama
- Zip / Postal Code: 35630
- Country: United States
- Contact:
Re: Letters a Shortcut for Buttons
Glenn/Dieter,
Just an FYI:
This code will not work for anything before Internet Explorer 9. We tried this a couple of years ago and got dinged by some users still using IE8 due to the stability. Don't know if this will come into play for Dieter, but thought I'd throw that out there.
Just an FYI:
This code will not work for anything before Internet Explorer 9. We tried this a couple of years ago and got dinged by some users still using IE8 due to the stability. Don't know if this will come into play for Dieter, but thought I'd throw that out there.
- Glenn
- Profound Logic Staff Member
- Posts: 124
- Joined: Mon Apr 14, 2014 4:08 pm
- First Name: Glenn
- Last Name: Hopwood
- Company Name: Profound Logic Software
- State / Province: Ohio
- Country: United States
- Contact:
Re: Letters a Shortcut for Buttons
Eric,
Thank you for the warning.
Glenn
Thank you for the warning.
Glenn
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Letters a Shortcut for Buttons
Profound UI provides an API, addEvent(), that you should consider using instead of document.addEventListener() since some older browsers don't support addEventListener(). The addEvent() API solves that.
To handle older Internet Explorer versions in your event routine, you need to handle the event being global vs. a parameter, and the keyCode being called 'which'. Basically, Internet Explorer never followed the standards, so it has it's own way of doing everything -- as newer versions came out, they made it mode and more compatible with the standards (often breaking applications that were written specifically for IE, causing people to stick with older versions.) Now, of course, IE is such a mess Microsoft is trying to discontinue it completely. But, anyway... I digress...
Try coding like this and it should work on all browsers:
To handle older Internet Explorer versions in your event routine, you need to handle the event being global vs. a parameter, and the keyCode being called 'which'. Basically, Internet Explorer never followed the standards, so it has it's own way of doing everything -- as newer versions came out, they made it mode and more compatible with the standards (often breaking applications that were written specifically for IE, causing people to stick with older versions.) Now, of course, IE is such a mess Microsoft is trying to discontinue it completely. But, anyway... I digress...
Try coding like this and it should work on all browsers:
Code: Select all
addEvent(document, "keydown", function(event) {
event = event || window.event;
var key = event.which || event.keyCode;
if(key == 89) {
// 'Y' key pressed
pui.click("btnYes");
}
if(key == 78) {
// 'N' key pressed
pui.click("btnNo");
}
});
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Letters a Shortcut for Buttons
Also bear in mind that if you attach the event at the document level (as I did above) it will remain until the event is removed. so when you switch to other screens, etc, the code will still be there trying to run on those screens as well.
If you want it to apply to only one screen, you should do one of these:
1) Attach the event to a widget rather than the whole screen. (The keydown event will only fire if that widget has focus when the key is presssed.)
-or-
2) Remove the event with the removeEvent() API when the screen is submitted.
If you want it to apply to only one screen, you should do one of these:
1) Attach the event to a widget rather than the whole screen. (The keydown event will only fire if that widget has focus when the key is presssed.)
-or-
2) Remove the event with the removeEvent() API when the screen is submitted.
-
- Experienced User
- Posts: 122
- Joined: Tue May 22, 2012 6:45 am
- First Name: Dieter
- Last Name: Schröder
- Company Name: Ecclesia Holding GmbH
- State / Province: Outside Canada/USA
- Country: Germany
- Contact:
Re: Letters a Shortcut for Buttons
Thank you for all anwers.
I will try the suggestions.
(We don't use IE. We use Chrome.)
Dieter
I will try the suggestions.
(We don't use IE. We use Chrome.)
Dieter
-
- Experienced User
- Posts: 116
- Joined: Wed Sep 05, 2012 11:14 am
- First Name: Eric
- Last Name: Hill
- Company Name: Integrated Corporate Solutions
- Phone: 256-760-8239
- Address 1: 501 S Wood Avenue
- City: Florence
- State / Province: Alabama
- Zip / Postal Code: 35630
- Country: United States
- Contact:
Re: Letters a Shortcut for Buttons
Scott,
On the removeEvent() - is that all that needs to be entered or would you need something like
removeEvent(document, "keydown");
or something similar?
Thanks!!!!
On the removeEvent() - is that all that needs to be entered or would you need something like
removeEvent(document, "keydown");
or something similar?
Thanks!!!!
-
- Experienced User
- Posts: 2711
- Joined: Wed Aug 01, 2012 8:58 am
- First Name: Scott
- Last Name: Klement
- Company Name: Profound Logic
- City: Milwaukee
- State / Province: Wisconsin
Re: Letters as Shortcut for Buttons
to find the documentation for the removeEvent() API, start here:
http://www.profoundlogic.com/docs
In the upper-right there's a field that says "Search". If you type removeEvent into that field it should take you right to the page. Let me know if this doesn't work for you, or if you have questions that are not answered by the documentation.
http://www.profoundlogic.com/docs
In the upper-right there's a field that says "Search". If you type removeEvent into that field it should take you right to the page. Let me know if this doesn't work for you, or if you have questions that are not answered by the documentation.
-
- Experienced User
- Posts: 116
- Joined: Wed Sep 05, 2012 11:14 am
- First Name: Eric
- Last Name: Hill
- Company Name: Integrated Corporate Solutions
- Phone: 256-760-8239
- Address 1: 501 S Wood Avenue
- City: Florence
- State / Province: Alabama
- Zip / Postal Code: 35630
- Country: United States
- Contact:
Re: Letters as Shortcut for Buttons
Scott,
I found that earlier but what I used in the parameters did not work. I did my addEvent exactly as you have above just changing what keycodes I needed. I coded the removeEvent like this in the onsubmit event:
removeEvent(document, "keydown", event);
It did not work correctly. I went to another screen and as soon as I hit one of my keycodes it tried to perform my pui.click(). What did I miss?
Thanks!!!!!
I found that earlier but what I used in the parameters did not work. I did my addEvent exactly as you have above just changing what keycodes I needed. I coded the removeEvent like this in the onsubmit event:
removeEvent(document, "keydown", event);
It did not work correctly. I went to another screen and as soon as I hit one of my keycodes it tried to perform my pui.click(). What did I miss?
Thanks!!!!!
Who is online
Users browsing this forum: No registered users and 2 guests