Probably (not tested for side effects in the wild) by using an OnObjectKeystroke trigger (Instead of OnObjectExit) and a test If [ Get ( TriggerKeystroke ) = Char (9) ], basically writing your own OnObjectExit method.
Or have OnObjectKeystroke set a flag, then exit the field, so your OnObjectExit kicks in, checks for the flag and branches correspondingly.
OK, I'm sufficiently frustrated by this that I'm replying to myself. I'm using the script shown below, and AFAICT, I'm doing everything I'm supposed to do to test for incoming keystrokes, but when I use Script Debugger while trying to activate the script, I find that:
• the topmost "if" statement isn't activated when I press enter.
• the middle one is bypassed when I press shift-tab.
• the bottom one is ignored when I just press an ordinary tab.
Thus, control never even gets to the "Commit Records" or "Go to Field" steps. In fact, if I run the script the way you see it here, the cursor just stays flashing in the "Addr Street" field and can't be extracted at all, by any method, without deactivating every step in the script.
As we used to say in the Old Country, WTF!?
1. Is the script triggered by OnObjectExit? Get ( TriggerKeytroke) only gives a result when used with the OnKeystroke triggers. Thus my suggestion to listen for selected keystrokes, then pass control to OnObjectExit if you detect one
2. True and False are keywords, not string expressions, so they don't work if put them in quotes – or more precisely, both will evaluate to false.
Just a thought about a different approach to your problem.
When your user tabs from one field to another, the target field remains active and can be checked by Get(ActiveFieldName). If the user has typed 'Enter', or clicked outside any fields, this function will provide an empty result. So by testing for an entry in this field, you can confirm that the 'Tab' key has been used.
However, you will also need to check if the user has clicked in a different field, one not the next in the tab order. So a script trigger OnObjectEnter can be used to see if the current active field is the one that follows the previous field in the tab order.
Then, in the same script, use a Global Variable to set the name of the next field in the tab order, using a calc that has a case statement for each field name, loading the next field name, when the current name matches. If the result of Get(ActiveFieldName) does not match the contents of the Global Variable, then the user has clicked in a different field.
I hope this gives you some ideas on a different approach.
Best wishes - Alan Stirling, London UK.
Sorry. But it's pretty basic to want a script to run when you press enter, return or tab.
We do it every time we google. And for this to be such a convoluted thing to accomplish, is pretty stupid if you ask me.
It just makes me want to drop the software in the trash.
It's not convoluted at all. The OnKeystroke trigger provides that capabiity out of the box.