wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes How to invoke 'PrtSc' Key in JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to invoke Watch "How to invoke New topic

How to invoke 'PrtSc' Key in JAVA

Ramesh Kumar Swarnkar
Ranch Hand

Joined: Sep 15, 2003
Posts: 84
I need to invoke a 'PrtSc' command of keyboard from a Java program. So that it can capture the entire screen-contents as an image. The Java-code should be such that while running in a loop and it will capture the screen as image at every 2 seconds .

I will be very grateful if someone, on this intelligent forum, can suggest me the solution in JAVA.

looking forwards - thanks in advance !!!

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24183

The only way to use the keyboard's PrScr key would be to use a robot. With sensors and motors and such. No other way to physically press a key that I can think of!

But... if what you're actually interested in is making screen grabs, then just check out the createScreenCapture() method of the java.awt.Robot class.

[Jess in Action][AskingGoodQuestions]
Ramesh Kumar Swarnkar
Ranch Hand

Joined: Sep 15, 2003
Posts: 84
let me check....robot
John de Michele

Joined: Mar 09, 2009
Posts: 600
Or, you could look in the java.awt.event.KeyEvent class for KeyEvent.VK_PRINTSCREEN. If you needed to automate something, you could use that with Selenium to simulate a keypress of the Print Screen key.

It is sorta covered in the JavaRanch Style Guide.
subject: How to invoke 'PrtSc' Key in JAVA
Similar Threads
Capturing ScreenShot of the the Active Window
Printing the applet screen
capture image
Capturing an image to system clipboard
Any idea capturing mouse cursor with Robot