How can I modify the "inputdlg" function to make the "Enter" key synonymous with the "OK" button in MATLAB R2016a?
    13 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
    MathWorks Support Team
    
 il 30 Ott 2012
  
    
    
    
    
    Modificato: MathWorks Support Team
    
 il 27 Apr 2023
            I am using the "inputdlg" function to enter data. When I am finished typing in a field, I would like to press "Enter" to close the dialog. Currently, the only way to close the dialog without using the mouse is to Tab through all of the fields until the OK button is active and then press "Enter".
Risposta accettata
  MathWorks Support Team
    
 il 1 Ago 2016
        Modifying the "inputdlg" function to make pressing the "Enter" key mimic the behavior of clicking the "OK" button requires extensive changes to inputdlg.m.
These changes have been implemented in the attached file, newid.m. You will need to save the file to the same directory as inputdlg.m. To find this directory, enter the following at the MATLAB Command Prompt:
which -all inputdlg
Since it is dependent on several private functions, newid.m will only work if stored in this location. After adding newid.m to this directory, you may have to execute 'rehash toolboxcache' at the MATLAB Command Prompt.
When you execute the following code, you will notice that "Enter" causes the exact same behavior as "OK":
prompt = {'Enter matrix size:','Enter colormap name:'};
dlg_title = 'Input for peaks function';
num_lines = 1;
def = {'20','hsv'};
answer = newid(prompt,dlg_title,num_lines,def);
If your MATLAB code uses newid.m and you wish to deploy your code as a Standalone executable using MATLAB Compiler, you need to make sure that "newid.m" is present in the same directory as your MATLAB code.  This is because MATLAB Compiler's dependency function does not pick up functions from paths such as '<matlabroot>\toolbox\matlab\uitools'.
2 Commenti
  Abhishek Pandey
    
 il 13 Mag 2016
				
      Modificato: MathWorks Support Team
    
 il 27 Apr 2023
  
			Hi Lockywolf! This seems to work for me in MATLAB R2016a. If you are still facing issues with this, feel free to contact MathWorks Technical Support. They should be able to help you with this.
- Abhishek
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Software Development Tools in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


