Using Keyboard Shortcuts in Oracle Apex

Introduction:

This post shows an example of how to add keyboard shortcuts using JavaScript in Oracle Apex. Using a little piece of JavaScript in the Apex page, you can assign keys like Shift, Ctrl, Alt, Options, and Command to perform particular functions in your application. Adding these functionalities also enables the users to save a lot of time.

Procedure:

The following steps shows an example of displaying the report based on the short keys in Oracle Apex page.

  • Create a report region(either it can be a Classic/Interactive report). Then add the below piece of code in the region attribute. This is because report should not be visible to the user until they use the key board shortcuts.

Region Attributes : style= “display:none;”

  • Create a HTML region and add the following code for key recognition and display report on pressing shortcut key. [Shortcut key used Ctrl + S]

 

<html>

<head>

    <script>

        function test(e) {

            e = e || window.event; //Get event

            if (e.ctrlKey) {

                var c = e.which || e.keyCode; //Get key code

                switch (c) {

                    case 83: // Block Ctrl+S

                        e.preventDefault(); // Prevents Default Fuctionality

                        e.stopPropagation();

                        $(“#TEST_REPORT”).dialog(); // Opens Dialog

                }

            }

        };

    </script>

</head>

 <body onkeydown=”javascript:test(event);”> </body>

 </html>

This post uses the HTML and JavaScript to make work of using shortcut keys in Oracle Apex.

Conclusion:

This post also explains how to prevent the default functionality of shortcut keys and overwrite the custom functionality. Moreover, the above code can be reused in the any of the Apex version.

Recent Posts