Mouse coordinates

15 views
Skip to first unread message

Alessia Mazzucchelli

unread,
May 7, 2021, 5:54:52 AMMay 7
to E-Prime
Hi Everyone!
I'm programming an experiment in which I must track mouse coordinates X and Y when the mouse button is pressed, but I'm having troubles with the script. 
I used this code: 

'Part 1: record mouse coordinates
'Declare pointer variable to hold coordinates
Dim ptMouse As Point
'Declare counter for mouse clicks
Dim mouseClicks As Integer

mouseClicks = CollectResponse.InputMasks(1).Responses.Count

If mouseClicks > 0 Then
'Show mouseclick on E data
c.SetAttrib "mouseclick", mouseClicks

'Declare variable for mouse response data
Dim ResponseX As MouseResponseData
Dim posx As Integer
'Collect coordinates
Set ResponseX = CMouseResponseData(CollectResponse.InputMasks.Responses(1))
c.SetAttrib "ResponseX", ResponseX.CursorX

'Set posX with X coordinate and show the variable on edata
posx = ResponseX.CursorX
c.SetAttrib "posx", posx

'Same with Y
Dim ResponseY As MouseResponseData
Set ResponseY = CMouseResponseData(CollectResponse.InputMasks.Responses(1))
Dim posy As Integer
c.SetAttrib "ResponseY", ResponseY.CursorY
posy = ResponseY.CursorY
c.SetAttrib "posy", posy
End If

'If ppt didn't click
If mouseClicks <= 0 Then  
c.SetAttrib "mouseclick", mouseClicks
'Set posx and posy as 0
posx=0
posy=0
End If


'log response coordinates
Dim theMouseResponseData As MouseResponseData
Set theMouseResponseData = CMouseResponseData(CollectResponse.InputMasks.Responses(1))

If Not theMouseResponseData Is Nothing Then

c.SetAttrib "X", theMouseResponseData.CursorX
c.SetAttrib "Y", theMouseResponseData.CursorY
c.SetAttrib "posx", theMouseResponseData.CursorX
c.SetAttrib "posy", theMouseResponseData.CursorY

End If

'Release references
Set theMouseResponseData = Nothing


but as soon as I implemented the possibility for ppt to not click, it started giving me errors and the code won't work anymore (It doesn't collect either mouseclick, nor the coordinates).
It also shows an error message for this line: Set theMouseResponseData = CMouseResponseData(CollectResponse.InputMasks.Responses(1))
and the error is: "the value for the INDEX parameter is either invalid or is not within range for this collection". 
Thanks in advance for any help! 

Best, 
Alessia 

Reply all
Reply to author
Forward
0 new messages