# ListenChar() and GetChar() fail under &quot;matlab -nodesktop&quot;

**URL:** <https://psychtoolbox.discourse.group/t/listenchar-and-getchar-fail-under-quot-matlab-nodesktop-quot/1025>\
**Category:** Uncategorized\
**Created:** [August 29, 2007, 8:31am UTC](https://psychtoolbox.discourse.group/t/listenchar-and-getchar-fail-under-quot-matlab-nodesktop-quot/1025 "2007-08-29T08:31:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![e\_flister](https://avatars.discourse-cdn.com/v4/letter/e/e36b37/32.png) [@e\_flister](https://psychtoolbox.discourse.group/u/e_flister)\
**Post date:** [August 29, 2007, 8:31am UTC](https://psychtoolbox.discourse.group/t/listenchar-and-getchar-fail-under-quot-matlab-nodesktop-quot/1025/1 "2007-08-29T08:31:01Z")

</div>

hey mario-  
(using winxp sp2, 2007a, 3.0.8.148604056)  
i'm trying to run some code that uses ListenChar()/GetChar() from a  
matlab started under "-nodesktop". i try typing into my commandwindow  
and neither ListenChar(2) nor GetChar(0) works -- the characters just  
appear in the commandwindow and are not detected by the code. in a  
matlab started without "-nodesktop", everything is fine.  
  
  
if i try to execute the test from line 66 of PsychBasic\ListenChar.m  
(or line 225 of PsychBasic\GetChar.m), i get:  

> \>\> exist('commandwindow', 'builtin')

ans =  
  
 0  
  
  
even though:  

> \>\> which commandwindow

C:\MATLAB\R2007a\toolbox\matlab\codetools\commandwindow.m  
  
  
note that:  

> \>\> exist('commandwindow')

ans =  
  
 2  
  

> \>\> help exist

 EXIST Check if variables or functions are defined.  
 EXIST('A') returns:  
 0 if A does not exist  
 1 if A is a variable in the workspace  
 2 if A is an M-file on MATLAB's search path. It also returns 2 when  
 A is the full pathname to a file or when A is the name of an  
 ordinary file on MATLAB's search path  
  
[...]  
  
  
thus, the line that follows the builtin test for commandwindow in both  
files:  
"builtin('commandwindow', msg);"  
  
yields:  
??? Cannot find builtin function 'commandwindow'  
  
(this assumes the variable 'msg' was defined, which it is not).  
  
SO. if i disable the tests and just execute "commandwindow," focus  
does indeed get sucked to my (nondesktop) commandwindow. but this  
does not rescue the "-nodesktop" function.  
  
also note, under "-nodesktop":  
  
» usejava('jvm')  
  
ans =  
  
 1  
  
» usejava('awt')  
  
ans =  
  
 1  
  
» usejava('swing')  
  
ans =  
  
 1  
  
» usejava('desktop')  
  
ans =  
  
 0  
  
-erik
