How do I send keystrokes from MATLAB to another application that was invoked using the bang(!) operator?
    13 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    MathWorks Support Team
    
 am 8 Mär. 2012
  
    
    
    
    
    Bearbeitet: MathWorks Support Team
    
 am 4 Nov. 2020
            I have invoked an application using the bang(!) operator in MATLAB on Windows, and would like to send keystrokes to this application from MATLAB. As a proof of concept, I would like to see this example implemented for a text editor.
Akzeptierte Antwort
  MathWorks Support Team
    
 am 4 Nov. 2020
        
      Bearbeitet: MathWorks Support Team
    
 am 4 Nov. 2020
  
      If you are running MATLAB on a Windows machine, you can use the WScript.Shell COM interface to send keystrokes to your application. For example, for Notepad, you would use the following code:
h = actxserver('WScript.Shell');
h.Run('notepad'); %Invokes notepad.exe
pause(3); %Waits for the application to load.
h.AppActivate('Notepad'); %Brings notepad to focus
h.SendKeys('hello world~'); %Sends keystrokes
h.SendKeys('^s'); % save file
pause(3);
h.SendKeys('test.txt~'); % save as 'test.txt' and return
h.SendKeys('%{F4}'); % close Notepad Alt+F4
For more information on symbol mapping to keystrokes, refer to the following URL:
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu View and Analyze Simulation Results finden Sie in Help Center und File Exchange
			
	Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
