Disable Keybord Buttons

is it possible to disable the print screen button when my program is in use?

[83 byte] By [The_Undeada] at [2007-11-27 11:28:00]
# 1

No.

Why oh why?

dwga at 2007-7-29 16:19:22 > top of Java-index,Java Essentials,New To Java...
# 2

ok...well im making an app for someone and they wanted to disable the print screen button

The_Undeada at 2007-7-29 16:19:22 > top of Java-index,Java Essentials,New To Java...
# 3

What if they use a camera to photograph the screen ;-)

BigDaddyLoveHandlesa at 2007-7-29 16:19:22 > top of Java-index,Java Essentials,New To Java...
# 4

well it wouldnt be as high quality, i just know that thats wha he wanted

The_Undeada at 2007-7-29 16:19:22 > top of Java-index,Java Essentials,New To Java...
# 5

actually, this is interesting, because i know I've played some games before online where printscreen did not work, and i had to go to a menu and click on a button everytime i wanted a snap shot. so it might be possible, and funny thing is, i think it was a game written in java.

I dont have enough knowledge to instruct on how to do it, but if you have the app running, and you click printscreen, you could have your keyboard listener ignore it? dont know if that would work, and then if they try going around it by being on the desktop and printing the screen you could make it so the app minimizes when it's not selected?

anyways good luck...

PlasmaLinka at 2007-7-29 16:19:22 > top of Java-index,Java Essentials,New To Java...
# 6

> actually, this is interesting, because i know I've

> played some games before online where printscreen did

> not work, and i had to go to a menu and click on a

> button everytime i wanted a snap shot. so it might

> be possible, and funny thing is, i think it was a

> game written in java.

>

> I dont have enough knowledge to instruct on how to do

> it, but if you have the app running, and you click

> printscreen, you could have your keyboard listener

> ignore it? dont know if that would work, and then if

> they try going around it by being on the desktop and

> printing the screen you could make it so the app

> minimizes when it's not selected?

>

> anyways good luck...

I think ill try that.

The_Undeada at 2007-7-29 16:19:22 > top of Java-index,Java Essentials,New To Java...
# 7

Better yet, tell the people giving you the idiotic requirement that it's an idiotic requirement.

1) It can still be circumvented thru what's been mentioned already

2) Don't mess with the user's wishes. If they want to print the screen, don't make it harder for them to do it (and they still will be able to in one way or another). It's not hurting anything to let them print it. They're "printing" it in their minds when they see it on the screen. A paper copy of that mental image isn't hurting anything.

warnerjaa at 2007-7-29 16:19:22 > top of Java-index,Java Essentials,New To Java...
# 8

> Better yet, tell the people giving you the idiotic

> requirement that it's an idiotic requirement.

> 1) It can still be circumvented thru what's been

> mentioned already

> 2) Don't mess with the user's wishes. If they want to

> print the screen, don't make it harder for them to do

> it (and they still will be able to in one way or

> another). It's not hurting anything to let them print

> it. They're "printing" it in their minds when they

> see it on the screen. A paper copy of that mental

> image isn't hurting anything.

honestly.. wtf. What if its for security reasons so that images of what is going on in the app don't get out?

and plus, the user seems to be asking for it to be disabled...

PlasmaLinka at 2007-7-29 16:19:22 > top of Java-index,Java Essentials,New To Java...
# 9

>

>

> honestly.. wtf. What if its for security reasons

That makes it worse. If it's really a "security" issue then the problem should be addressed in a more suitable fashion.

cotton.ma at 2007-7-29 16:19:22 > top of Java-index,Java Essentials,New To Java...
# 10

> Better yet, tell the people giving you the idiotic

> requirement that it's an idiotic requirement.

> 1) It can still be circumvented thru what's been

> mentioned already

> 2) Don't mess with the user's wishes. If they want to

> print the screen, don't make it harder for them to do

> it (and they still will be able to in one way or

> another). It's not hurting anything to let them print

> it. They're "printing" it in their minds when they

> see it on the screen. A paper copy of that mental

> image isn't hurting anything.

It is my clients request that it be disabled, i would rather not tell hi its stupid. I can how ever tell him its not possible.

The_Undeada at 2007-7-29 16:19:22 > top of Java-index,Java Essentials,New To Java...
# 11

you'll probably find the OS handles the printscreen key before it gets to the jvm.

perhaps if you reset the clipboard (after the prinscreen key gets to the jvm).

something like this

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.awt.datatransfer.*;

import java.io.*;

class Testing

{

public void buildGUI()

{

JFrame f = new JFrame();

f.getContentPane().add(new JScrollPane(new JTextArea(10,20)));

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.pack();

f.setLocationRelativeTo(null);

f.setVisible(true);

KeyboardFocusManager.getCurrentKeyboardFocusManager()

.addKeyEventDispatcher(new KeyEventDispatcher(){

public boolean dispatchKeyEvent(KeyEvent ke){

if(ke.getID() == KeyEvent.KEY_RELEASED)

{

if(((KeyEvent) ke).getKeyCode() == KeyEvent.VK_PRINTSCREEN)

{

System.out.println("print screen");

Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new DummyImage(new ImageIcon("test.gif").getImage()), null);

}

}

return false;

}

});

}

class DummyImage implements Transferable

{

private Image image;

public DummyImage(Image img){image = img;}

public DataFlavor[] getTransferDataFlavors(){return new DataFlavor[]{DataFlavor.imageFlavor};}

public boolean isDataFlavorSupported(DataFlavor flavor){return DataFlavor.imageFlavor.equals(flavor);}

public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException

{

if (!DataFlavor.imageFlavor.equals(flavor)){throw new UnsupportedFlavorException(flavor);}

return image;

}

}

public static void main(String[] args){new Testing().buildGUI();}

}

Michael_Dunna at 2007-7-29 16:19:22 > top of Java-index,Java Essentials,New To Java...
# 12

that wont work. no java solution will.

what if i made the program half the screen and then gave focus to another program on the other half. if i hit printscreen it wouldnt register

with the java program but id still get the image. : P

TuringPesta at 2007-7-29 16:19:22 > top of Java-index,Java Essentials,New To Java...
# 13

> you'll probably find the OS handles the printscreen

> key before it gets to the jvm.

> perhaps if you reset the clipboard (after the

> prinscreen key gets to the jvm).

>

> something like this

>

> > import java.awt.*;

> import java.awt.event.*;

> import javax.swing.*;

> import java.awt.datatransfer.*;

> import java.io.*;

> class Testing

> {

>

>public void buildGUI()

> {

>JFrame f = new JFrame();

> f.getContentPane().add(new JScrollPane(new

> JTextArea(10,20)));

>

> .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

>f.pack();

> f.setLocationRelativeTo(null);

>f.setVisible(true);

>

> eyboardFocusManager.getCurrentKeyboardFocusManager()

> .addKeyEventDispatcher(new

> KeyEventDispatcher(){

>public boolean dispatchKeyEvent(KeyEvent ke){

>if(ke.getID() == KeyEvent.KEY_RELEASED)

>{

> if(((KeyEvent) ke).getKeyCode() ==

> KeyEvent.VK_PRINTSCREEN)

>{

>System.out.println("print screen");

>

> oolkit.getDefaultToolkit().getSystemClipboard().setCon

> tents(new DummyImage(new

> ImageIcon("test.gif").getImage()), null);

> }

>

>return false;

>

>});

>

>class DummyImage implements Transferable

> {

>private Image image;

> public DummyImage(Image img){image = img;}

> public DataFlavor[]

> getTransferDataFlavors(){return new

> DataFlavor[]{DataFlavor.imageFlavor};}

> public boolean isDataFlavorSupported(DataFlavor

> flavor){return

> DataFlavor.imageFlavor.equals(flavor);}

> public Object getTransferData(DataFlavor flavor)

> throws UnsupportedFlavorException, IOException

>{

> if (!DataFlavor.imageFlavor.equals(flavor)){throw

> new UnsupportedFlavorException(flavor);}

>return image;

>

>}

> public static void main(String[] args){new

> Testing().buildGUI();}

> }

>

I will try that

The_Undeada at 2007-7-29 16:19:22 > top of Java-index,Java Essentials,New To Java...
# 14

>> I will try that

and you would be foolish to.

TuringPesta at 2007-7-29 16:19:22 > top of Java-index,Java Essentials,New To Java...
# 15

Why dont you people use some assembly executables and embed it into your code? Is it possible in Java to embed something like SYSTEM (disable.exe)?

kraton_mayaa at 2007-7-29 16:19:26 > top of Java-index,Java Essentials,New To Java...
# 16

yes it sure is. using JNI.

TuringPesta at 2007-7-29 16:19:26 > top of Java-index,Java Essentials,New To Java...
# 17

Oops my bad!

Not yet ready to dive into JNI. (whatever the hell it is). But as you suggested, it is possible.

Thanks.

kraton_mayaa at 2007-7-29 16:19:26 > top of Java-index,Java Essentials,New To Java...
# 18

> Oops my bad!

>

> Not yet ready to dive into JNI. (whatever the hell it

> is). But as you suggested, it is possible.

>

And as already pointed out, it won'd matter one iota whether you do it or not.

People are resourceful, and will find a way around it.

In the meantime they'll be mightily annoyed and blacklist you for any future business.

jwentinga at 2007-7-29 16:19:26 > top of Java-index,Java Essentials,New To Java...
# 19

> yes it sure is. using JNI.

I'm glad it only took about 20 posts for this to come up.

kmangolda at 2007-7-29 16:19:26 > top of Java-index,Java Essentials,New To Java...
# 20

> > yes it sure is. using JNI.

>

> I'm glad it only took about 20 posts for this to come up.

I was hoping it wouldn't come up at all. *Shudder*

BigDaddyLoveHandlesa at 2007-7-29 16:19:26 > top of Java-index,Java Essentials,New To Java...
# 21

> I was hoping it wouldn't come up at all. *Shudder*

yea like i said: "(you could try) and you would be foolish to."

TuringPesta at 2007-7-29 16:19:26 > top of Java-index,Java Essentials,New To Java...
# 22

Actually this reminds me of a time in college when a friend of mine

was bragging that his band was streaming their music on Real

player so that no one could download it and steal it.

While he carried on and on I recorded the sound card's "what you hear"

channel and in 3 minutes i had his stupid song emailed to him.

Moral: you're never as clever as you think. let people do what they will.

TuringPesta at 2007-7-29 16:19:26 > top of Java-index,Java Essentials,New To Java...