Wednesday, July 4, 2012

Using keyboard inputs during EEG inspection in EEGLAB

It is often frustrating to click through hundreds of trials while inspecting EEG data using EEGLAB. While it might be possible to hack into the Matlab code to use keyboard inputs to flip through each trial, there is an easy solution to it. We can achieve this by designating the mouse clicks needed to specific keyboard inputs. This can be done by writing up a short script for Autohotkey (Windows) or Autokey (Linux). I have not tried this on a Mac OS but I believe there is a similar program that can do this. The data inspection process was much faster and less stressful to my wrist after I started using the keyboard to do the job.


First, let's have a look at the mouse clicks we need for data inspection (while plotting one trial at a time):
1. Go to previous trial.
2. Go to next trial.
3. Mark/unmark trial for removal.


The mouse click locations are given in the flowing figure:




Now all we have to do is map these mouse events to certain keyboard inputs. I like to use keys ",", ".", and "/" for actions 1, 2, and 3 respectively. 


For Autohotkey the script is simply


; This is a comment
; The two numbers represent the x, y position any pixel in the area of interest. 
; On windows, this can be found  using "AutoIt3 Window Spy" which is installed with Autohotkey.

;Left (action 1)
,::Click 380, 971
;Right (action 2)
/::Click 609, 971
;Mark (action 3)
.::Click 737,612


In order to do this in Autokey, one would have to add three separate scripts using the following API:


click_relative(self, x, y, button)
Send a mouse click relative to the active window


Usage: mouse.click_relative(x, y, button)


Parameters:
x - x-coordinate in pixels, relative to upper left corner of window
y - y-coordinate in pixels, relative to upper left corner of window
button - mouse button to simulate (left=1, middle=2, right=3)


For each mouse action, just add one line of code with the appropriate pixel position and mouse button and designate a hotkey to each script.


No comments:

Post a Comment