# KbEventGet() not working

**URL:** <https://psychtoolbox.discourse.group/t/kbeventget-not-working/3585>\
**Category:** Programming Help\
**Created:** [December 16, 2020, 5:14pm UTC](https://psychtoolbox.discourse.group/t/kbeventget-not-working/3585 "2020-12-16T17:14:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SaFroeli](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@SaFroeli](https://psychtoolbox.discourse.group/u/SaFroeli)\
**Post date:** [December 16, 2020, 5:14pm UTC](https://psychtoolbox.discourse.group/t/kbeventget-not-working/3585/1 "2020-12-16T17:14:00Z")

</div>

Hi all,

I would like to monitor keyboard input of the 4 letters s,x,k and m with KbEventGet(). The code is similar to this:

```
deviceIndex = []; 
keysOfInterest = zeros(1, 256);
keysOfInterest(KbName('s')) = 1;
keysOfInterest(KbName('x')) = 1;
keysOfInterest(KbName('k')) = 1;
keysOfInterest(KbName('m')) = 1;

KbQueueCreate(deviceIndex, keysOfInterest);
KbQueueStart(deviceIndex);

KbEventFlush(deviceIndex);
   
% wait for a keypress
key_pressed = false;
while ~key_pressed
    key_ev = KbEventGet(deviceIndex);
    if (~isempty(key_ev) && key_ev.Pressed)
        key_pressed = true;
    end
    
    % wait for 1 msec to prevent system overload
    WaitSecs('Yieldsecs', 0.001);                
end

```

So in my understanding, the code above should leave the while-loop as soon as one of the four keys is pressed. This does however not work. I remain stuck within the while-loop no matter how often I press one of the keys, as KbEventGet() does not seem to notice any keyboard input.

What am I doing wrong?

I am using PTB 3.0.16 - Flavor: beta - Corresponds to SVN Revision 10582 with MATLAB R2019a on Manjaro Linux, Kernel 4.14.209-1-MANJARO.

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [December 16, 2020, 6:03pm UTC](https://psychtoolbox.discourse.group/t/kbeventget-not-working/3585/2 "2020-12-16T18:03:30Z")

</div>

Your code looks right to me, and it works for me as you expect (on Windows). Does KbQueueDemo work for you? Can you update to the latest PTB (3.0.16 is unsupported)?

---

<div class="post-metadata">

**Author:** ![SaFroeli](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@SaFroeli](https://psychtoolbox.discourse.group/u/SaFroeli)\
**Post date:** [December 16, 2020, 7:44pm UTC](https://psychtoolbox.discourse.group/t/kbeventget-not-working/3585/3 "2020-12-16T19:44:54Z")

</div>

I updated PsychToolbox and now it works fine. Thanks!
