keyStroke command with the Robot class in Processing

edited August 2016 in OpenBCI_GUI
I am trying to translate alpha waves into a spacebar keystroke so I can switch slides on a Powerpoint presentation. I have everything working so far: alpha waves are correctly identified, there is a time delay so I don't issue too many commands, and I can trace the commands using the println command. However, every time I try to switch the println command out with a keyPress command, the program blows up. Is there an issue with using the keyStroke command in processing? Will it be possible to control another program via Processing or should I use a different program?

Thanks in advance! These forums have been vital!

Comments

  • If it helps, my code in question is here:

    if (detectedPeak[Ichan].SNR_dB >= detection_thresh_dB) {
              detectedPeak[Ichan].threshold_dB = detection_thresh_dB;
              detectedPeak[Ichan].isDetected = true;
              isDetected = true;
              r.setAutoWaitForIdle(true);
              r.setAutoDelay(5000);
              r.keyPress(KeyEvent.VK_SPACE); //fire spacebar event
              r.keyRelease(KeyEvent.VK_SPACE);
              }
              
              
              
    and the error I get is:

    java.lang.RuntimeException: java.lang.NullPointerException
    at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
    at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103)
    at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:206)
    at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
    at javax.media.opengl.Threading.invoke(Threading.java:191)
    at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541)
    at processing.opengl.PJOGL.requestDraw(PJOGL.java:688)
    at processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1651)
    at processing.core.PApplet.run(PApplet.java:2256)
    at java.lang.Thread.run(Unknown Source)
              
              
              
              
              
              
  • Oyyy found out that I needed to place it in a try statement. All is well!
  • dandan Chicago
    In what file and line do I insert code to perform a basic function when processing detects an alpha wave spike?

    Let's say I want to type the letter 'a' on the keyboard when an alpha wave spike is detected. How would this be achieved?



    My setup:

    SRB2: Reference on A1
    BIAS: Bias on A2
    7N: Red wire placed at O1


  • wjcroftwjcroft Mount Shasta, CA
    @dan , I merged your question into this existing thread on that subject. See the previous posts. You will be using the Java (Processing) class called Robot.

  • dandan Chicago
    Awesome. Thank you, @wjcroft. Do I add this to the OpenBCI_GUI > EEG_Processing file?

    #devnoob
  • wjcroftwjcroft Mount Shasta, CA
    edited December 2015
    Dan, hi. Let's mention @quiksilver10152 on this post, so he can see your question. You can also send a PM private message to him by clicking on his name and then the Message button on his profile. It's possible he can send or make available his modified OpenBCI_GUI source files.

    Another excellent resource are Chip @chipaudette 's posts about alpha detection, on his blog,

    https://www.google.com/search?q="eeg+hacker"+alpha+detection

    Chip's source code is available on his Github

    https://github.com/chipaudette

    William
Sign In or Register to comment.