Controlling Keyboard Keys (Pressing & Releasing) with Matlab code
Code for this:
import java.awt.Robot;
import java.awt.event.*;
t = Robot();
t.keyPress(KeyEvent.VK_CAPS_LOCK);
t.keyRelease(KeyEvent.VK_CAPS_LOCK);
Explanation of the Code:
# import java.awt.Robot; --> it will import from the java.awt module the Robot class.
See full documentation of this class at here.
# import java.awt.event.*;-->it will import all the classes from the java.awt.event module.
See full documentation of this class at here.
# t = Robot();--> Assigning the variable 't' Robot class.
# t.keyPress(KeyEvent.VK_CAPS_LOCK);--> This will perform the Key Pressing Action of CAPS LOCK key.
# t.keyRelease(KeyEvent.VK_CAPS_LOCK);--> This will perform the Key Pressing Action of CAPS LOCK key.
NOTE: if you want to turn the CAPS LOCK again off, then again you should append the code with the following 2 statements.
t.keyPress(KeyEvent.VK_CAPS_LOCK);
t.keyRelease(KeyEvent.VK_CAPS_LOCK);
Hope you found this computer automation part of MATLAB interesting.
clc;
clear all; import java.awt.Robot;
import java.awt.event.*;
t = Robot();
t.keyPress(KeyEvent.VK_CAPS_LOCK);
t.keyRelease(KeyEvent.VK_CAPS_LOCK);
Explanation of the Code:
# import java.awt.Robot; --> it will import from the java.awt module the Robot class.
See full documentation of this class at here.
# import java.awt.event.*;-->it will import all the classes from the java.awt.event module.
See full documentation of this class at here.
# t = Robot();--> Assigning the variable 't' Robot class.
# t.keyPress(KeyEvent.VK_CAPS_LOCK);--> This will perform the Key Pressing Action of CAPS LOCK key.
# t.keyRelease(KeyEvent.VK_CAPS_LOCK);--> This will perform the Key Pressing Action of CAPS LOCK key.
NOTE: if you want to turn the CAPS LOCK again off, then again you should append the code with the following 2 statements.
t.keyPress(KeyEvent.VK_CAPS_LOCK);
t.keyRelease(KeyEvent.VK_CAPS_LOCK);
Hope you found this computer automation part of MATLAB interesting.
0 comments: