VAS...Continuous Input and Wait#.Resp Functions

Daniel.J.Bates at wheaton.edu Daniel.J.Bates at wheaton.edu
Mon Jun 23 22:43:26 UTC 2003


Hello again...

This is an update regarding my previously posted VAS code.  I (along with my co-
workers) have been refining on this code over the last couple of days and have
found a way to program a continuous key-press and to avoid Wait#.Resp
functions.  I have included a copy of the code below.  As you can see, it is
split up into two sections.  The first section is a Global User Script and
directs Microsoft Windows (using API) to accept continuous input from the
keyboard.  Instead of using keys 1-5, I have changed the VAS code to only
accept F1, F2, and F3.  The second section includes an inner-ScriptObject
loop.  K1, K2, and K3 represent the code that asks the computer if a particular
key has been pressed.  When that key is pressed, its value <> 0.  It then runs
the appropriate SlideObject and changes the image on the screen.  (All this
without straddling the SlideObject with GoTo labels and inline code.)
Interestingly, it only does this when the duration of the SlideObject is > 0
ms. It is not necessary to tell the SlideObject to accept data from the
keyboard.  When F2 (named K2) is pressed, the program records the location of
the vertical bar (as a percentage), changes the stimulus that appears on the
screen, and moves the vertical bar back to the center of the scale.  The 1000
ms Sleep command prevents the subject from skipping over stimuli (if it is not
present, the continuous input function thinks that the subject has pressed F2
>1x and records the default location of the vertical bar for each skipped
stimulus).  Let me know if you have any questions.

------------------------------------------------------------------------
Global User Script: Researched and Developed at Michigan State University by
David McFarlane.
------------------------------------------------------------------------
global const VK_F1 = &H70
global const VK_F2 = &H71
global const VK_F3 = &H72

Declare Function GetAsyncKeyState Lib "user32" Alias "GetAsyncKeyState" (ByVal
vKey As Long) As Integer
----------------------------------------------------------------------

-----------------------------------------------------------------------
VAS-Loop: Developed at Michigan State University by Laurence Bates and Daniel
Bates.
----------------------------------------------------------------------

 Dim k1, k2, k3 As Long
 Dim ScreenWidth As Integer
 Dim NewButtonPosn As Integer
 Dim ButtonPosn As Integer
 Dim RealSliderWidth As Integer
 Dim slrLeft As Integer
 Dim slrRight As Integer
 Dim Tag As String

 ScreenWidth = 640
 slrLeft = 144
  slrRight = 492
 NewButtonPosn = 319

 Do

  k1 = GetAsyncKeyState(VK_F1) and &H8000
  k2 = GetAsyncKeyState(VK_F2) and &H8000
  k3 = GetAsyncKeyState(VK_F3) and &H8000

  If k1 <> 0 then
     If ButtonPosn >= slrLeft + 4 Then
       NewButtonPosn = ButtonPosn - 4
     Else
       NewButtonPosn = slrLeft
     End If
     CSlideImage(Slide1.States.Item("Default").Objects(3)).X = NewButtonPosn
  End if
  If k3 <> 0 then
     If ButtonPosn <= slrRight - 4 Then
       NewButtonPosn = ButtonPosn + 4
     Else
       NewButtonPosn = slrRight
     End If
     CSlideImage(Slide1.States.Item("Default").Objects(3)).X = NewButtonPosn
  End if

  Slide1.Run

  ButtonPosn = NewButtonPosn

  Loop until k2 <> 0

  If k2 <> 0 then
    Tag = Str((ButtonPosn - slrLeft) * 100 / (slrRight - slrLeft)) + " percent"
    c.SetAttrib "EasMBResponse" , Tag
    CSlideImage(Slide1.States.Item("Default").Objects(3)).X = 319
  End if

 Sleep 1000
----------------------------------------------------------------------



More information about the Eprime mailing list