MouseTracker elements let you track where on the page is your participant’s mouse cursor every few milliseconds.
Creation:
newMouseTracker("mouse")
The only parameter is the element name ("mouse") which is optional. Make sure to call log
to collect data in the results file.
The coordinates are reported in the results file as a long compressed string. The string always start with xXyYwWhH, where X and Y are numbers corresponding to the mouse coordinates when recording starts, and W and H correspond to the page’s width and height. It then continues with sequences of tT+A-B bits, where T corresponds to the number of milliseconds since the last bit, and +A and -B, which can be positive (+) or negative (-) correspond to how many pixels the mouse has moved horizontally and vertically, respectively. This script illustrates how to decompress the string in R, assuming the results datatable was previously subset to MouseTracker rows only:
[php]timestamps_get_response <- vector() xpos_get_response <- vector() ypos_get_response <- vector() for(row in 1:nrow(results)){ time <- 0 stream <- as.character(results[row,"Value"]) pos <- data.frame(time=c(time),x=as.numeric(gsub("^x(\\d+)y.+$","\\1", stream)), y=as.numeric(gsub("^.+y(\\d+)w.+$","\\1", stream))) ptime <- time counter <- 1 px <- pos[1,'x'] py <- pos[1,'y'] for(s in (strsplit(stream,'t')[[1]][-1])){ row <- strsplit(gsub("^(\\d+)([+-]\\d+)([+-]\\d+)$","\\1 \\2 \\3",s),' ') ntime <- as.numeric(ptime+as.numeric(row[[1]][1])) nx <- as.numeric(px+as.numeric(row[[1]][2])) ny <- as.numeric(py+as.numeric(row[[1]][3])) pos <- rbind(pos, data.frame(time=ntime,x=nx,y=ny)) ptime <- ntime px <- nx py <- ny counter <- counter +1 } times <- toString(pos[["time"]]) timestamp <- paste("[", times, "]", sep = "") timestamps_get_response <- c(timestamps_get_response, timestamp) xpos <- toString(pos[["x"]]) xpos_str <- paste("[", xpos, "]", sep = "") xpos_get_response <- c(xpos_get_response, xpos_str) ypos <- toString(pos[["y"]]) ypos_str <- paste("[", ypos, "]", sep = "") ypos_get_response <- c(ypos_get_response, ypos_str) } results$timestamps <- timestamps_get_response results$xpos <- xpos_get_response results$ypos <- ypos_get_response[/php]
Commands
[yadawiki-list category=”NonTest command,MouseTracker element”]
Tests
[yadawiki-list category=”Test command,MouseTracker element”]
Index
- Tutorial
- Commands by element categories
- Standard Element Commands
- Audio element
- Button element
- Canvas element
- DropDown element
- EyeTracker element
- Function element
- Html element
- Image element
- Key element
- MediaRecorder element
- Scale element
- Selector element
- Text element
- TextInput element
- Timer element
- Tooltip element
- Var element
- Video element
- Youtube element
- Special clear command
- Special end command
- Global PennController Commands
- PennController
- PennController.AddHost
- PennController.AddTable
- PennController.CheckPreloaded
- PennController.Debug
- PennController.DownloadVoiceButton
- PennController.FeedItems
- PennController.Footer
- PennController.GetTable
- PennController.GetURLParameter
- PennController.Header
- PennController.InitiateRecorder
- PennController.PreloadZip
- PennController.ResetPrefix
- PennController.SendResults
- PennController.Sequence
- PennController.SetCounter
- PennController.Template
- Installing PennController
- Ontology
- Aesthetics
- Preloading resources
- ZIPped resources
- Spreadsheet (CSV)
- Canvas creation
- Setup for audio recordings collection