Skip to Content

How to attach keyboard function keys to button press event?

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Jan 24, 2014 at 12:13 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 03, 2015 at 06:25 AM

    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

    Add comment
    10|10000 characters needed characters exceeded