Results 1 to 5 of 5

Thread: Window Focus

  1. #1
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default 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:
    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 )
                {
                }	
                
          
             }
             
             
          }
    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.
    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.

  2. #2
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    What if I made this window from another, could I then use requestFocus() to force my window to be on top?

  3. #3
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    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);
                  }

  4. #4
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    6

    Default

    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.

  5. #5
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    You mentioned force quit, how does the user accomplish that?

Similar Threads

  1. switch focus to another window
    By tuansoibk in forum AWT / Swing
    Replies: 1
    Last Post: 11-15-2009, 05:22 AM
  2. change url in parent window from child window
    By rakesh_n_mehta in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-09-2009, 12:17 PM
  3. how to let the shell window in SWT lose focus
    By kents in forum SWT / JFace
    Replies: 2
    Last Post: 06-25-2009, 10:34 AM
  4. how can i move one frame window to another window
    By santhosh_el in forum AWT / Swing
    Replies: 8
    Last Post: 06-10-2009, 03:36 PM
  5. Focus
    By Marty in forum AWT / Swing
    Replies: 1
    Last Post: 05-31-2007, 02:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •