How to make enter and space works in modal like nsb.msgbox

Hi guys
I am trying to do a personal msgbox, like NSB.Message Box, but with my style, bigger, etc…
I did focus in each button with tab key works, but space and enter, like NSB.Messagebox, not yet

Any tip to do it easy?

I’m not sure I understand your question.

If I needed to make a replacement for NSB.MsgBox, I’d use a Bootstrap Modal

Bsmodal1 .

I would like to make a custom form for messagebox, but I want the keyboard to work, many of our users use our app on google chrome and like to give tab to navigate between the buttons and enter … the tab key and give the focus I already got, but I wanted to make the enter work, without having to use window_onkeypress, as it works in nsb.messagebox with several buttons

I use a custom input form for text entry using window_onkeydown(e), not keypress. I can capture all keys used including alt-ctrl combos, a bit tricky but can be done. “Enter” is ok when using single line entry text objects. If you need to use text areas then forget capturing the Enter key, it will be needed for new lines. I haven’t done this yet, but I think I’ll use the Tab key to move between the text object and of the command buttons (OK, Clear and Cancel). Then the Enter key can activate the button.

This form is positioned to the top, or close to the top, of the form and centered in the window. A form width no greater than 320px will work ok on most devices (or use progressive methods). Use the .focus() on the input control when showing the form so the on-screen keyboard pops up. This also sets the cursor in the input box so entry is ready to go.

I either hide the underlying form or use a modal method when showing the input form. Using this text data entry method on desktops allows the user to stay on the physical keyboard most of the time, not requiring the use of the mouse.

Function window_onkeydown(e)
  If keycapture = "off" Then Exit Function  'Before showing the input text, form "keycapture" is set to "on" and upon leaving the form set it to "off". 
  keyval = e.code
  If keyval = "Enter" Then 
    'Do what you want the Enter key to do, you can also add an "OK" button on the form to do the same thing.
	'Now determine where to put the captured text,
	'I usually put it into a label that looks like a text entry object, and then hide the special input form. Selecting this label (false input object) causes the input form to be displayed.
  ElseIf keyval = "Escape" Then 
  'do somehthing relating to the Escape key
  ElseIf keyval = "KeyN" Then 
  'you just pressed the letter N
  ElseIf keyval = "Tab" Then 
  'you can set the focus somewhere else here
  End if


1 Like

Tip : If you’re pasting code, html or config files, surround the code with triple back ticks (```), before the first line and after the last one. It will be formatted properly.