Improve the accessibility and usability of your ToolBook HTML content by providing keyboard shortcuts in addition to the onscreen navigation.
The Challenge
I recently had a customer who contacted me for just a short project. They had already created more than 10 books of ToolBook content and just needed help with small but important thing before they could complete the project.
What they wanted was to enable the learner to use Keyboard combinations to navigate between the pages:
- LEFT arrow key - navigate to the previous page
- RIGHT arrow key - navigate to the next page
- END key - exit the course (with a prompt to confirm if the learner is certain that they want to quit)
While I can’t share the exact solution I decided to create a similar that I will share with you here.
Download the ToolBook sample
As always you can see the live sample here and download the tbk file from the download page.
The solution
As their content only had one background per book I chose to a solution which involved adding an object - a button - to that background as this would be the easiest way to implement the solution.
Here goes:
Create a standard button on the background, name it exit and format it to your liking.
Note while the button is named exit and has a caption saying exit it is NOT an exit button from the catalog)
Use the Action Editor and add the following actions to the button:
--------------------------------------------------------------------------------
Actions for Button "Exit" of Background id 0
--------------------------------------------------------------------------------
-- On key up... ----------------------------------------------------------------
Comment: Tomas Lund, ToolBookConsulting.com, July 2008
Comment: Navigate when the user press the arrow keys or the end key while pressing the ALT key
If keyCode = 37
Comment: User pressed the Left arrow key
Go to the previous page
Else if keyCode = 39
Comment: User pressed the Right arrow key
Go to the next page
Else if keyCode = 35
Comment: User pressed the END key, now trigger self is the same as the user clicking the button
Trigger Self
End if
-- On load page... -------------------------------------------------------------
Comment: The Keyup event is not being handled in the on KeyUp handler on the button unless it has the focus
Comment: So we set the focus to the button whenever we enter a page.
Execute SetFocus() of Self
-- On click... -----------------------------------------------------------------
Define local variable "res" (Initial value: "")
Comment: Tomas Lund, ToolBookConsulting.com
Comment: July 2008
Comment: Check if the learner really wants to quit then exit and suspend the lesson
Display confirmation: "Are you sure you wish to exit the course?"; store response in res
If res
Exit (LMS: suspend lesson) (LMS: Student can resume) (LMS: no automatic navigation)
End if
All the code above is in the Exit button in the sample file.
That is all there is to it!
Update August 4
Based on a question below I have updated the article.
The question goes: "Is there a list of keycodes?"
The answer is that there is a list in the helpfile which contain the keycodes. (search for "Key constants (table)"). However this approach is faster:
Create the following code with the actions editor.
On Keyup
Alert Keycode
go to reader and press the key you want to know the keycode of and it will be alerted.
The Caveats
Ironically the next and previous buttons in Navigation panel has the “Exclude from tab order” property set to true. This is because the On Keyup button handler on the Exit doesn’t work if the other navigation buttons has the focus.
It is ironic because the Exclude from tab order” property is designed to make keyboard navigation easier, however most ToolBook’ers I talk with does not like the dotted box which surrounds the object and hence they disable it. In this case my customer had this disabled as well so this wasn’t a problem. Another way of ensuring that focus isn’t much of a problem is to add the On KeyUp handler on each page, but in this case that would have to big a task to do manually for my client.
Requirements vary so this is just one approach, there are other ways of implementing keyboard shortcuts in ToolBook content than what I have described here.
Let me know if you find this article useful by adding a comment or suggestions below.
Tomas