Can anyone kindly help me out?
I want to create an app, like user access control(UAC) application. When UAC is running we cannot click anywhere on the screen, unless we close UAC window. Also we cannot press any key to do anything, like window key or any of the function key. So I want to create a similar application using C ++ code to control keyboard and mouse, that only mouse and keyboard is enabled in my application window and disable outside and unless i do not close my app i cant perform any other task. My application would be just a graphical simple window with a close button, and obove mentioned controls.
A long time ago Windows supported system modal dialogs. These would prevent the user from interacting with other windows including the desktop. Microsoft removed support for this a long time ago due to the problems that it caused.
Now when Windows needs to provide a system modal window for UAC they use a bit of desktop magic. To simulate a system modal window UAC does something like this.
Create a bitmap and take a snapshot of the current desktop.
Darken the bitmap
Create a new desktop
Set the new desktop as the currently active one.
Create a window the size of the new desktop and draw the bitmap in it.
Now they have a desktop that looks like the old and acts as if it were a system model window. You are then free to create a child window to grab input from the user. The example below shows how to create a desktop and switch to it and should be a good starting point for what you want to do
// TODO: Make a copy of the current desktop
// Prepeare a new desktop and activate it
HDESK oldDesktop = GetThreadDesktop(GetCurrentThreadId());
HDESK desktop = CreateDesktop(L"MyDesktop", NULL, NULL, 0, GENERIC_ALL, NULL);
SwitchDesktop(desktop);
// TODO: Create the window that draws the snapshot of the old desktop
// TODO: Create a dialog with buttons and stuff
// Since we don't have a window sit for 5 seconds staring at blank screen
Sleep(5000);
// Switch back to the old desktop and destroy the one we created
// ALERT: If we crash or exit without doing this you will need to
// restart windows
SwitchDesktop(oldDesktop);
CloseDesktop(desktop);
You can find more information on the desktop related API's
Related
I'm trying to make an overlay on the screen using JavaFX and an issue I'm having is that whenever my overlay pops up, it steals focus from whichever program I'm currently in. The issue with this is that my overlay allows the user to simulate keyboard key presses using the robot class (like an on-screen keyboard) and without keeping the focus in the original window, the typed characters have nowhere to go. I've tried setting the modality to none, but that's also the default option and it doesn't seem to be doing anything. Would putting my JavaFX scene in a JFrame work or is there some better way to do it only in JavaFX?
Try this
when focused -> compute what you want to
then call Stage.toBack(); //the currently focused window prior to yours will gain focus back
I want to set a window invisible but focused for a fraction of seconds.
I'm writing a key board emulator using Robot class as a part of project for detecting key loggers.
Keyboard emulator should not disrupt the normal work of the user, so I want to set a hidden window focused for a short span so that the keys entered by the robot class received by the hidden window instead of normal user applications.
Is there any way to do this in Java when window is actually invisible? How to do this? at least in windows platform?
How about transparent full screen window in case the above thing is not possible?
My base paper: http://www.atlantis-press.com/php/download_paper.php?id=9980
Is there any way to do this in Java when window is actually invisible?
No. Not in pure Java at least.
How about transparent full screen window in case the above thing is not possible?
A transparent window does not receive events. So again, no.
I have a full screen Window made like this
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
if (gs.length >= 1)
gs[1].setFullScreenWindow(frame);
else
gs[0].setFullScreenWindow(frame);
This puts the frame on the second monitor unless there is no second monitor in which case it puts the Window on the primary monitor
Now my problem is that I can't seem to find a way to push the window to the back and force it to loose focus to that other windows, dialogs and even things such as Google Chrome go in front of the window -- which could be a problem if the user starts the program without a secondary monitor plugged in or if the secondary monitor gets unplugged (in both cases the fullscreen Window ends up on the primary display)
Is there a way to give other windows, JFrames or whatever is needed focus above the Window?
Or is there some sort of Listener that I don't know about that will allow me to dispose of the fullscreen window in the event that it gets moved to the primary display (I have tried implementing ComponentListener in the class that extends Window)?
setFillScreen is a method used to set your program in "full screen exclusive mode", meaning, your application has exclusive control over the screen, and no other program's should be rendered.
Do you actually just want to maximise the window instead? In which case you should be using Frame#setExtendedState and passing it Frame.MAXIMIZED_BOTH
You may also want to look at setUndecorated
Anyone have an idea how the Amazon mp3 app is displaying the player controls inside of the keyguard? I've been playing with some of the system alert and system overlay window parameters with now luck. The system alert will display over everything except the lock screen and the system overlay will display over the lock screen but in 4.0.3 and above you can not receive the touch events.
I have also seen options like WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG but it only seems to work for an activity; anything else I use it with gives me an exception that tells me that I can not use that flag with this type of window.
What I have noticed is that the player controls either replace or cover the keyguard clock and the player controls change size depending on the type of lock (like pattern lock or swipe lock). I've also noticed that the keyguard does not display my wallpaper anymore...
Any thoughts are welcome!
I've created a small application that allows the user to capture the screenshot and save the image at a user defined location. It also allows the user to capture the screenshot of the active window as well.
The issue is with the active window. I have learnt that Java does not provide a method to get the screenshot of the active window. So, I googled and found that developers have been using the Alt+PrntScrn to get the screenshot and get the image from the clipboard.
The code is the following one:
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_PRINTSCREEN);
robot.keyRelease(KeyEvent.VK_PRINTSCREEN);
robot.keyRelease(KeyEvent.VK_ALT);
Thread.sleep(1500);
RenderedImage image = (RenderedImage)getClipboard();
saveToImage(image,targetLocation);
Now what happens is that when the Alt key is pressed by the robot class, the focus goes on the toolbar of the application of which the user wants to get the screenshot and the screenshot is taken of the toolbar and not that of the window that the user has focus on.
Please advise on how to solve this problem.
If this were my application, I'd use JNA -- Java Native Access to get the active window and its size and then use that information to allow the robot to grab the image.