When a user开发者_运维问答 presses the ESC key, I need to display a prompt. How can I do this in Lotus Notes client?
Can you elaborate? Is this for one application, one form or the whole Lotus client? Why would you want to disable the esc key?
In the Queryclose event you can get a handle to the close event. Continue = false will prevent the form from closing:
Sub Queryclose(Source As Notesuidocument, Continue As Variant)
msgbox "the message"
End Sub
** The original question changed (by a moderator) from it's original intent, which asked to detect AND ignore ESC key press in Lotus Notes. **
You need to use the "QueryClose" event (as others have mentioned), but how do you identify a "legitimate" way to close the form ? We need some logic to distinguish between someone actually clicking a button to "legitimately" close the form, and if someone hits the escape key or the "X" button in the window bar.
So, you need to use 2 form events, and an action button to do this.
In the QueryOpen event of the form
Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
Dim session As New NotesSession
Call session.SetEnvironmentVar("CloseDoc",0,True)
End Sub
Your QueryClose event needs to look like this
Sub Queryclose(Source As Notesuidocument, Continue As Variant)
Dim session As New NotesSession
Dim iCloseDoc As Integer
iCloseDoc = session.GetEnvironmentValue("CloseDoc", True)
If iCloseDoc <> 1 Then
continue = False
End If
End Sub
And you need to have an action button called "Close", on the form with this in it.
@SetEnvironment("CloseDoc";"1");
@PostedCommand([FileCloseWindow])
The LotusScript alternative looks like this
Sub Click(Source As Button)
Dim ws As New notesUIWorkspace
Dim session As New NotesSession
Call session.SetEnvironmentVar("CloseDoc",1,True)
Call ws.CurrentDocument.Close
End Sub
Now what's going on ? When you open the form, I set an environment variable for "CloseDoc", (QueryOpen event). If the user hits the "ESC" key or even clicks the "X" on the form to close the window the QueryClose event triggers.
When a request to close the form is detected, the QueryClose event then runs. I retrieve the "CloseDoc" environment variable which, in this case is still 0 (zero). If it's not equal to 1 then the close form will be aborted. You can add a messagebox there if you like.
Now the only way for the user to successfully close the form is for them to press the "Close" button. Which first sets the CloseDoc environment variable to 1, then call NotesUIDoc.close(). Although I am not a big fan of environment variables, it is handy in the case as you are able to record user activity without modifying the current document or another document. (That would be even messier, because you would have to clean up temporary documents, or you are forced to make changes to the document which won't work if the user only has reader access to the database or the current document).
This is relatively clean as the control is managed via a discrete envrionment variable that adds no overhead to the database performance and will not get in the way of any other functionality of applications. Some suggestions in the comments advises the use of global variables instead of environment variables and this quite is appropriate if you're using LotusScript exclusively, but if you have a mixture of formula and lotusScript, environment variables are common to both. But it's upto the developer to determine which.
This is one way I have over the years forced the user to click a specific button to close the document, and ignore "ESC" keys or the "X" button int he form window bar without any annoying messages and is free of performance issues.
精彩评论