Copy link to clipboard
Copied
I would like to call a function (script) in the form after pressing a key or key combination.
I'd appreciate a simple example.
It is possible, in theory, to know whether Ctrl or Shift (not Alt, though) were held down when the user types into a text field. I tried it, though, and it only worked with Shift, and even then only when it was not a pre-defined shortcut of the application. In short, it's not very reliable.
The other approach is better, I think, and there is actually a way of keeping track of what was the last field a user clicked into. You can add a script to the On Blur event of all the fields in the table t
...Copy link to clipboard
Copied
This can't be done at the document level. And the JavaScript model does not provide a simple way to add keyboard shortcuts.
It is possible to create a menu item that contains a shortcut by creating a new menu item. If an "&" is placed in front of any letter in the label of the menu item, then that letter will be displayed with an underscore, which indicates that pressing that key will activate the menu item, when the menu is displayed.
That's as good as you can get, and menu items cannot be created from a document script.
Copy link to clipboard
Copied
Thanks for the answer,
I want to get this functionality at the form design level. I have a large table in it and various possible actions to be performed on individual rows or cells, and creating a button for each such situation is terribly tedious and obscures the form. Creating one button, in turn, will result in the loss of information from where the action was triggered, i.e. from which place in the table, because if I press the button, the table element will lose focus a moment earlier ... and thus information from where it was triggered. So it would be wise to create a "hot key" that I can call at any time.
The solution may be a piece of script placed in the keystroke event handler, provided that you can recognize what was pressed (e.g. Ctrl+Alt+1) and call a function at the same time for a given field, treat these keys as invisible.
Copy link to clipboard
Copied
It is possible, in theory, to know whether Ctrl or Shift (not Alt, though) were held down when the user types into a text field. I tried it, though, and it only worked with Shift, and even then only when it was not a pre-defined shortcut of the application. In short, it's not very reliable.
The other approach is better, I think, and there is actually a way of keeping track of what was the last field a user clicked into. You can add a script to the On Blur event of all the fields in the table that keeps their name saved into a doc-level variable. When you click the button you access that variable to know what field was last "visited" by the user, and then you can act based on that info. It's a bit tricky, but should work better than the key-combination approach.
Copy link to clipboard
Copied
I was thinking exactly the same š
Although, unfortunately, you need to add these few lines to each field in the event after losing focus..
Thank you for the explanation, although I thought there was an elegant way, but at least I won't waste another day searching the internet for "how to do it".... š
Copy link to clipboard
Copied
Depending on the field names that shouldn't be too difficult. You could use a loop to process all of them, adding the same line of code to each one of their On Blur event. The best would be to just have it call a doc-level function, where all the actual code will be, of course.