cancel
Showing results for 
Search instead for 
Did you mean: 

How to attach keyboard function keys to button press event?

ChandraMahajan
Active Contributor
0 Kudos

Hello,

I am having requirement to attach keyboard function keys to button press event. for eg. button X should get clicked on pressing function key F5

How we can achieve this in SAPUI5? Kindly let me know.

Regards,

Chandra

Accepted Solutions (1)

Accepted Solutions (1)

jmoors
Active Contributor
0 Kudos

I think you could use a jQuery library like hotkeys to bind to the function key browser event, or use the UI5 onKeydown event on the control and then use the fireEvent method trigger the press event on the button?

https://github.com/jeresig/jquery.hotkeys

https://sapui5.hana.ondemand.com/sdk/#docs/guide/EventsInControls.html

Many thanks,

Jason

ChandraMahajan
Active Contributor
0 Kudos

Thanks Jason for the info. I will try this!

Regards,

Chandra

Former Member
0 Kudos

have to findout how to do that??

Answers (1)

Answers (1)

Former Member
0 Kudos

Write this following code in your onInit() method:


Here we are handling the keypress event on Control + S key combination.


$(document).keydown(function(evt){
  
if (evt.keyCode==83 && (evt.ctrlKey)){
       evt
.preventDefault();
       alert
('worked');
  
}
});


Regards,

Shubham