How to Simulate keyboard key inputs?
    33 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Kevin
      
 el 11 de Abr. de 2011
  
I am interested in simulating a keyboard input using .m code.
How would I go about simulating typing and other keyboard inputs?
Similar to this, but with the keyboard instead of the mouse.
Thanks,
Kevin
0 comentarios
Respuesta aceptada
  Walter Roberson
      
      
 el 11 de Abr. de 2011
        Java Robot class.
7 comentarios
  Walter Roberson
      
      
 el 9 de Sept. de 2012
				ying xing FENG commented "It works for text. But not for other active windows other than Matlab. For eg. on screen key borad. Any idea? "
  Jan
      
      
 el 9 de Sept. de 2012
				Más respuestas (5)
  Garrett Cassidy
 el 14 de Ag. de 2019
        Does anyone know how to emulate a ; or a \  ?  I can emulate keystrokes, but the ‘VK_OEM_1´input to keyPress is undefined.
Thanks
0 comentarios
  Kevin
      
 el 11 de Abr. de 2011
        2 comentarios
  Paulo Silva
      
 el 11 de Abr. de 2011
				
      Editada: dpb
      
      
 el 5 de Jul. de 2020
  
			I think VK means virtual key but I'm not sure
  Jan
      
      
 el 11 de Abr. de 2011
				KeyEvent.VK_W is the [W] key - there is no upper or lower case *key*! You need the [Shift] key to create uppercase characters:
robot.keyPress(java.awt.event.KeyEvent.VK_SHIFT)
robot.keyPress(java.awt.event.KeyEvent.VK_W)
robot.keyRelase(java.awt.event.KeyEvent.VK_W)
robot.keyRelease(java.awt.event.KeyEvent.VK_SHIFT)
Remember: It is only a robot and it s(t)imulates the keyboard...
  ali
 el 30 de Nov. de 2011
        Hi Paulo,
regarding"execute my code and Matt code on the command line of matlab (not in a script) :)"
I am going to kill an running script through simulating Ctrl+C which is written as a function like this:
import java.awt.Robot; import java.awt.event.*; SimKey=Robot; SimKey.keyPress(java.awt.event.KeyEvent.VK_CONTROL); SimKey.keyPress(java.awt.event.KeyEvent.VK_C); SimKey.keyRelease(java.awt.event.KeyEvent.VK_CONTROL);
how can I call it? when I call this function it does not work? Thanks, Ali
1 comentario
  Amirhosein Ghenaati
 el 5 de Dic. de 2014
        hello i want to execute kmplayer then first launch kmplayer then use java robot to push space it will open media folder. my program stop when kmp starts and and when i terminates kmp space chracter will be printed in editor. here is my simple program and i dont know whats problem please help me in this situation
import java.awt.Robot
import java.awt.event.*
keys = Robot;
keys.setAutoDelay(1000)  
[status currdir] = system('cd C:\Users\IranZamin\Documents\MATLAB\temporary');
[status result] = system('KMPlayer.lnk');
keys.keyPress(java.awt.event.KeyEvent.VK_SPACE ) 
keys.keyRelease(java.awt.event.KeyEvent.VK_SPACE ) 
keys.waitForIdle
0 comentarios
  Amirhosein Ghenaati
 el 19 de Dic. de 2014
        i tried to make exe version of key pressing with robot class but my exe file doesn't work and i dont know what i couldnt find relative .jar file for java robot class whats its name ?
0 comentarios
Ver también
Categorías
				Más información sobre Convert Image Type en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







