# using GetChar on Matlab 6 for Windows

**URL:** <https://psychtoolbox.discourse.group/t/using-getchar-on-matlab-6-for-windows/1303>\
**Category:** Uncategorized\
**Created:** [April 17, 2001, 10:13pm UTC](https://psychtoolbox.discourse.group/t/using-getchar-on-matlab-6-for-windows/1303 "2001-04-17T22:13:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [April 17, 2001, 10:13pm UTC](https://psychtoolbox.discourse.group/t/using-getchar-on-matlab-6-for-windows/1303/1 "2001-04-17T22:13:10Z")

</div>

Chien-Chung Chen has reported that the psychtoolbox function "GetChar"  
when called from MATLAB 6.0 for Windows hangs Matlab. Here is a  
short explanation of that problem and how to avoid it.  
  
The default frontend for Matlab 6 on Windows is written in Java and  
executes in a Java Virtual Machine (JVM). The JVM does not interact  
well with psychtoolbox dlls (mex files) which access the windows event  
queue. However, you can run a Matlab 6 command window without using  
the java stuff. To do that, invoke Matlab with the -nojvm option  
  
For example, because I have installed the Matlab executable here:  
C:\matlabR12\bin\win32\matlab.exe  
  
To launch Matlab I type at the Windows command line:  
C:\matlabR12\bin\win32\matlab.exe -nojvm  
  
Typing that (and then hitting the enter key) to launch Matlab is  
inconvenient. Instead, you can modify a shortcut (a thing which Mac  
users would call an alias) to launch Matlab with the -nojvm option.  
In Windows 2000, right-click on a Matlab shortcut icon and select the  
properties item from the pop-up menu. Under the 'shortcut' tab of the  
properties window, find the field named 'target'. The content of this  
fields specifies the path to the matlab executable. Append ' -nojvm'  
to the path and click the 'ok' button to close the properties window.  
(Note the space before before the hyphen in ' -nojvm'.)  
  
Henceforth, when you double-click on that shortcut to launch Matlab it  
will launch without the Java stuff. Be careful, if you launch Matlab  
some other way, it will not launch with the -nojvm option.  
  
Some people launch Matlab from the Start menu. The Matlab entry in  
the Start menu tree is a Windows shortcut which you can modify as  
described above. In Windows 2000 that start menu shortcut for Matlab  
is in:  
C:\Documents and Settings\All Users\Start Menu\Programs\MATLAB Release  
12  
  
These instructions might be slightly different for other varieties of  
Windows. For example, in windows 98 the start menu shortcut is in:  
C:\Windows\Start Menu\Programs\Matlab.  
  
You can find all Matlab shortcuts by using Window's find utility from  
the Start menu. You can also relabel shortcuts to identify them as  
the -nojvm and regular variety. You can create new shortcuts by  
right-clicking on a shortcut or on the Matlab executable and selecting  
"Create Shortcut" from the pop-up menu. (Shortcuts created from other  
shortcuts point to original executable, not to the shortcut).  
  
GetChar will get characters if you use -nojvm, but be warned that  
GetChar still occasionally misses some kepresses.  
  
Allen  
  
  
  
  

> \>Date: Mon, 2 Apr 2001 14:28:02 -0700 (PDT)  
> \>From: Chien-Chung Chen \<[ppanthers@...](mailto:ppanthers@...)\>  
> \>Subject: PsychToolbox bug report  
> \>To: David Brainard \<[brainard@...](mailto:brainard@...)\>  
> \>  
> \>David,  
> \>  
> \>'getchar' is not compatible with MATLAB 6.0 (Release  
> \>12). It hangs MATLAB. The 'screen' seems working fine  
> \>so far. BTW. Is there any progress on "playsound" for  
> \>Windows? I wrote a small utility to work around the  
> \>problem, but I would be happy that it is in the  
> \>toolbox so that I can make sure my codes work the same  
> \>under Windows or Mac.  
> \>

---

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [April 17, 2001, 10:45pm UTC](https://psychtoolbox.discourse.group/t/using-getchar-on-matlab-6-for-windows/1303/2 "2001-04-17T22:45:56Z")

</div>

This is a follow-up to my previous message about the -nojvm fix for getchar under  
Matlab 6.  
  
You can't edit .m files from the Matlab environment if you run Matlab with the  
-nojvm option. One way around this is to run two instances of Matlab, one with  
and one without -nojvm. Use the -nojvm instance to invoke .m files and use the  
other instance to edit .m files.  
  
 Allen  
  
  
  
"Allen W. Ingling" wrote:  
  

> \> Chien-Chung Chen has reported that the psychtoolbox function "GetChar"  
> \> when called from MATLAB 6.0 for Windows hangs Matlab. Here is a  
> \> short explanation of that problem and how to avoid it.  
> \>  
> \> The default frontend for Matlab 6 on Windows is written in Java and  
> \> executes in a Java Virtual Machine (JVM). The JVM does not interact  
> \> well with psychtoolbox dlls (mex files) which access the windows event  
> \> queue. However, you can run a Matlab 6 command window without using  
> \> the java stuff. To do that, invoke Matlab with the -nojvm option  
> \>  
> \> For example, because I have installed the Matlab executable here:  
> \> C:\matlabR12\bin\win32\matlab.exe  
> \>  
> \> To launch Matlab I type at the Windows command line:  
> \> C:\matlabR12\bin\win32\matlab.exe -nojvm  
> \>  
> \> Typing that (and then hitting the enter key) to launch Matlab is  
> \> inconvenient. Instead, you can modify a shortcut (a thing which Mac  
> \> users would call an alias) to launch Matlab with the -nojvm option.  
> \> In Windows 2000, right-click on a Matlab shortcut icon and select the  
> \> properties item from the pop-up menu. Under the 'shortcut' tab of the  
> \> properties window, find the field named 'target'. The content of this  
> \> fields specifies the path to the matlab executable. Append ' -nojvm'  
> \> to the path and click the 'ok' button to close the properties window.  
> \> (Note the space before before the hyphen in ' -nojvm'.)  
> \>  
> \> Henceforth, when you double-click on that shortcut to launch Matlab it  
> \> will launch without the Java stuff. Be careful, if you launch Matlab  
> \> some other way, it will not launch with the -nojvm option.  
> \>  
> \> Some people launch Matlab from the Start menu. The Matlab entry in  
> \> the Start menu tree is a Windows shortcut which you can modify as  
> \> described above. In Windows 2000 that start menu shortcut for Matlab  
> \> is in:  
> \> C:\Documents and Settings\All Users\Start Menu\Programs\MATLAB Release  
> \> 12  
> \>  
> \> These instructions might be slightly different for other varieties of  
> \> Windows. For example, in windows 98 the start menu shortcut is in:  
> \> C:\Windows\Start Menu\Programs\Matlab.  
> \>  
> \> You can find all Matlab shortcuts by using Window's find utility from  
> \> the Start menu. You can also relabel shortcuts to identify them as  
> \> the -nojvm and regular variety. You can create new shortcuts by  
> \> right-clicking on a shortcut or on the Matlab executable and selecting  
> \> "Create Shortcut" from the pop-up menu. (Shortcuts created from other  
> \> shortcuts point to original executable, not to the shortcut).  
> \>  
> \> GetChar will get characters if you use -nojvm, but be warned that  
> \> GetChar still occasionally misses some kepresses.  
> \>  
> \> Allen  
> \>  
> \> \>Date: Mon, 2 Apr 2001 14:28:02 -0700 (PDT)  
> \> \>From: Chien-Chung Chen \<[ppanthers@...](mailto:ppanthers@...)\>  
> \> \>Subject: PsychToolbox bug report  
> \> \>To: David Brainard \<[brainard@...](mailto:brainard@...)\>  
> \> \>  
> \> \>David,  
> \> \>  
> \> \>'getchar' is not compatible with MATLAB 6.0 (Release  
> \> \>12). It hangs MATLAB. The 'screen' seems working fine  
> \> \>so far. BTW. Is there any progress on "playsound" for  
> \> \>Windows? I wrote a small utility to work around the  
> \> \>problem, but I would be happy that it is in the  
> \> \>toolbox so that I can make sure my codes work the same  
> \> \>under Windows or Mac.  
> \> \>  
> \>  
> \> To Post a message, send it to: [psychtoolbox@...](mailto:psychtoolbox@...)  
> \>  
> \> To Unsubscribe, send a blank message to: [psychtoolbox-unsubscribe@...](mailto:psychtoolbox-unsubscribe@...)  
> \>  
> \> psychtoolbox web site: [http://color.psych.ucsb.edu/psychtoolbox/](http://color.psych.ucsb.edu/psychtoolbox/)  
> \>  
> \> Your use of Yahoo! Groups is subject to [http://docs.yahoo.com/info/terms/](http://docs.yahoo.com/info/terms/)
