OK. I’ve limited experience with this but have some info for you. First is the code from Pitonyak. This gets you the methods you need to code. Copy this code:
sPrefix = "sel_change_"
' sService = "com.sun.star.view.XSelectionChangeListener"
' sService = "com.sun.star.lang.XEventListener"
' sService = "com.sun.star.awt.XMenuListener"
sService = "com.sun.star.awt.XKeyHandler"
' sService = "com.sun.star.awt.XButton"
vService = CreateUnoListener(sPrefix, sService)
DisplayDbgInfoStr(vService.dbg_methods, ";", 35, "Methods")
Sub DisplayDbgInfoStr(sInfo$, sSep$, nChunks, sHeading$)
'Array to hold each string
Dim i As Integer
Dim j As Integer
'Junk integer variable for temporary values
Dim s As String
'holds the portion that is not completed
s = sInfo$
j = InStr(s, ":")
If j > 0 Then Mid(s, 1, j, "") 'Remove portion up to the initial colon
aInfo() = Split(s, sSep$, nChunks)
'Split string based on delimiter.
s = aInfo(UBound(aInfo()))
'Grab the last piece. Contains
If InStr(s, sSep$) < 1 Then
'the rest if there were too many.
s = ""
'If there were not, then clear s.
'If there was a delimiter then
ReDim Preserve aInfo(nChunks - 2)
'change array dimension to
'remove the extra last piece.
For i = LBound(aInfo()) To UBound(aInfo())'Look at each piece to remove
aInfo(i) = Trim(aInfo(i))
'leading and trailing spaces.
j = InStr(aInfo(i), CHR$(10))
'Some have an extra
If j > 0 Then Mid(aInfo(i), j, 1, "") 'new line that should be removed.
MsgBox Join(aInfo(), CHR$(10)), 0, sHeading$
Loop Until Len(s) = 0
Running the macro InspectListenerMethods will display the methods you need to incorporate into your code. sService is the the only thing you need to modify. It is currently set for XKeyHandler with others commented out. Easier for later examination. So if you run this three items need definition even if they don’t do anything (queryInterface can be ignored)- disposing, keyPressed and keyReleased. Knowing that, here is my key handler(working model):
global oXKeyHandler as object
if isNull(oXKeyHandler) then 'only if not jet running
oXKeyHandler = CreateUnoListener("KeyHandler_", "com.sun.star.awt.XKeyHandler")
if not IsNull(oXKeyHandler) then 'only if still running
oXKeyHandler = Nothing 'To know later this handler has stopped.
function KeyHandler_KeyPressed(oEvent) as boolean
'The entire objective of the key handler:
'On the menu, when the 'Enter' key is pressed
'don't move to the next field(cancel)
If (oEvent.KeyCode = 1280) Or (oEvent.KeyCode = 1284) Then
KeyHandler_KeyPressed = True 'cancel KeyPressed
KeyHandler_KeyPressed = False 'cancel KeyPressed
function KeyHandler_KeyReleased(oEvent) as boolean
'but when the 'Enter' key is released,
'execute the 'Key Released' event assigned in the control
If oEvent.KeyCode = 1280 Then
KeyHandler_KeyReleased = False 'cancel KeyReleased
KeyHandler_KeyReleased = True 'cancel KeyReleased
This was used in a menuing form in which I wanted the normal function of the Enter key to be overridden (next field & select it).
As you can see, XButton is one of the service selections. Start there and try Pitonayaks’ book again. This isn’t the easiest of sections.
Not sure why you are taking this approach. I should have realized this earlier. I’ve eluded to this in one of our previous posts but let you lead me astray (my fault not yours) with your mention of listeners & such. If your looking to see which button is doing the calling you can just set a variable. I’ve attached a (dumb) sample but it does display what I mean. The button pushed will only record the answer once and a different button pushed will add to the answer. PBTest.odb