Results 1 to 5 of 5
Thread: Window Focus
- 12-28-2009, 08:16 AM #1
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
Window Focus
I am trying to build sort of a "lock screen" on my computer. This screen would function just like the password screen on any windows computer. It would take up the whole screen(done that), ask for password input(done that), and not be able to be avoided(need help). My program will not let anyone to alt-tab, windows key, alt-f4, etc... What I cant get it to not let the user do is ctrl+alt+del, and ctrl+shit+esc(on Vista). Both will let them open the task manager which can be used to close the program. Is there any way to stop this? Here is my code:
I've tried to disable ctrl+shift+esc by having a Robot press esc, del, and ctrl beucase when i press esc, then ctrl then shift, it won't open. Same with del then press ctrl then alt with c+a+d. This didn't work, I guess only physically.Java Code:import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.JFrame; public class keydemoRun { public static void main( String args[] ) throws AWTException { Dimension screen = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); JFrame PassFrame = new JFrame(); PassFrame.setUndecorated(true); PassFrame.getRootPane().setWindowDecorationStyle(JRootPane.NONE); PassFrame.setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); PassFrame.setSize( (int)screen.getWidth(), (int)screen.getHeight() ); PassFrame.addKeyListener(new WindowLstnr()); PassFrame.addWindowFocusListener(new WindowLstnr()); PassFrame.addWindowStateListener(new WindowLstnr()); PassFrame.setVisible( true ); } static class WindowLstnr implements WindowFocusListener,WindowStateListener,KeyListener{ public void windowGainedFocus(WindowEvent e){ } public void windowLostFocus(WindowEvent e){ JOptionPane.showMessageDialog(null, "Error: FAILED", "Error", JOptionPane.ERROR_MESSAGE); //new CmdDemo("rundll32.exe user32.dll, LockWorkStation"); } public void windowStateChanged(WindowEvent e){ JOptionPane.showMessageDialog(null, "Error: FAILED", "Error", JOptionPane.ERROR_MESSAGE); //new CmdDemo("rundll32.exe user32.dll, LockWorkStation"); } public void keyPressed( KeyEvent event ) { if (event.getKeyCode() == 10) { System.exit(0); } new CmdDemo("rundll32.exe user32.dll, LockWorkStation"); } public void keyReleased( KeyEvent event ) { } public void keyTyped( KeyEvent event ) { } } }
One idea I had was to make is whenever the user pressed ctrl, esc, shift, del, ...etc, It would lock the computer. However, if the user presses the combination fast enough, it will be open once they unlock the computer and can close the program. Is there a way to force my program to be on top of the task manager? Any other ideas would be greatly appreciated. Also, If you test my program, press enter to close it.
- 12-28-2009, 08:45 PM #2
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
What if I made this window from another, could I then use requestFocus() to force my window to be on top?
- 12-28-2009, 09:11 PM #3
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
sorry, CmdDemo is a program I have. replace CmdDemo with:
Java Code:try { Process p=Runtime.getRuntime().exec("rundll32.exe user32.dll, LockWorkStation"); } catch(Exception e) { System.out.println(e); }
- 12-29-2009, 12:25 AM #4
Aside from using native code/methods/libraries, I don't see any way for a java app to prevent you from using things like force quit and ctrl-alt-del (thank god).
Pure java cannot take the OS controls over in most cases.
- 12-29-2009, 03:03 AM #5
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
Similar Threads
-
switch focus to another window
By tuansoibk in forum AWT / SwingReplies: 1Last Post: 11-15-2009, 05:22 AM -
change url in parent window from child window
By rakesh_n_mehta in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 07-09-2009, 12:17 PM -
how to let the shell window in SWT lose focus
By kents in forum SWT / JFaceReplies: 2Last Post: 06-25-2009, 10:34 AM -
how can i move one frame window to another window
By santhosh_el in forum AWT / SwingReplies: 8Last Post: 06-10-2009, 03:36 PM -
Focus
By Marty in forum AWT / SwingReplies: 1Last Post: 05-31-2007, 02:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks