Up to this point we have only considered scenarios in which the participant makes responses by clicking buttons on the screen. Depending on the kind of stimulus that we are presenting, we used a different function:

This gives us a family of four trial types that vary depending on the stimulus modality. In jaysire (and jsPsych), we can also vary the response modality. There are three supported response methods: buttons, key presses, and slider bars. If you want users to respond by pressing a key, the jaysire package includes the following family of functions:

If you would prefer a continuous valued response that uses a slider bar:

All of these functions work in approximately the same way, but there are slightly different arguments required to describe a button press, a key press, and a slider bar.

For example, when you specify the choices in a button press trial, what you’re doing is provide a character vector that contains the labels shown on each of the buttons. In contrast, when you specifiy the choices argument for a keyboard response trial, you’re giving the a vector that specifies which keys can be used to register a response. A common use case is to ask people to press “p” to respond with their left hand or “q” to respond with their right hand, which you can do by setting choices = c("p","q"). You can also specify keys numerically by using their javascript key code value. This is worth noting, because when the data are recorded, it will be the numeric key code that appears in the data set! Also note that jaysire contains the respond_any_key() function that allows the user to press any key to register a response, and the respond_no_key() button which makes it impossible the respond with the keyboard (this is useful if you want a trial that runs for a fixed duration)

To give you a sense of how these functions work, here is a very simple experiment that uses a button press trial, a keypress trial, and a slider trial:

library(jaysire)
resources <- system.file("extdata", "resources", package = "jaysire")

# the keypress trial is used as an instruction screen
keypress_trial <- trial_image_keyboard_response(
  stimulus = insert_resource("heart.png"),
  stimulus_height = 400,
  stimulus_width = 400,
  prompt = "<br>You will be asked judge the pleasantness of this image. Press any key to continue",
  choices = respond_any_key()
)

# use buttons to ask people to rate on a three-point likert scale
button_trial <- trial_image_button_response(
  stimulus = insert_resource("heart.png"), 
  stimulus_height = 400,
  stimulus_width = 400,
  choices = c("Unpleasant", "Neutral", "Pleasant") 
)

# use a slider to ask people to respond on a continuous valued scale
slider_trial <- trial_image_slider_response(
  stimulus = insert_resource("heart.png"), 
  stimulus_height = 400,
  stimulus_width = 400,
  labels = c("Most unpleasant", "Neutral", "Most Pleasant"),
  min = 0,
  max = 100,
  start = 50
)

# randomise the order of the two "substantial trials"
tests <- build_timeline(button_trial, slider_trial) %>%
  set_parameters(randomize_order = TRUE)

# build the experiment
build_experiment(
  timeline = build_timeline(keypress_trial, tests),
  resources = build_resources(resources),
  path = temporary_folder(), 
  on_finish = save_locally()
)

You can check out a working version of the experiment here.