Sign in to follow this  
Followers 0
ianim8

Intersecting ESC

18 posts in this topic

Good afternoon folks,

An AutoIt newbie here.

I have created a script that runs an application and switches it into full screen mode. Normally, while in full-screen mode, the 'ESC' button exits full-screen mode and return the user to the program interface. Instead, I would like to capture that 'ESC', and quit the application (exiting full-screen first if needed). I cannot seem to accomplish this. I am on Windows 7 by the way, in case that has any bearing on this.

I have tried using the following, stripped down to see if I can disable the 'Esc' key by capturing it and doing nothing. However, pressing 'Esc' still results in the program exiting full-screen mode and into the editor.

HotKeySet ("{Esc}", "EscPressed")
Func EscPressed()
EndFunc

Any suggestions would be greatly appreciated. Thanks.

Glen

Share this post


Link to post
Share on other sites

Why not just do ProcessClose() on the application when the Esc key is pressed? (Put the ProcessClose() inside your EscPressed().)

That way, the Esc will be read by the application, putting it in windowed mode, and then your script will close the application.

Share this post


Link to post
Share on other sites

I tried ProcessClose() but the program just exited fullscreen mode, the program did not close.

I have since tried replacing HotKeySet("{Esc}"... with HotKeySet("q"... to see if that would work in case the application was overriding the "Esc" key somehow. With "q" set as the hotkey, pressing q did nothing at all. Is there something set in my system perhaps that is getting in the way? Is this perhaps an issue between AutoIt and Windows 7?

Glen

Share this post


Link to post
Share on other sites

Is UAC enabled? Are you running your script with #RequireAdmin?

Share this post


Link to post
Share on other sites

Unfortunately I am not familiar with UAC or #RequireAdmin. Should I be using them?

Share this post


Link to post
Share on other sites

I added the #RequiredAdmin tag but nothing changed, tried both HotKeySet("{Esc}"... and HotKeySet("q"...

Share this post


Link to post
Share on other sites

#RequireAdmin should be used in some cases because the action will not be allowed if you aren't an administrator. UAC, or User Account Control, is something that comes with Windows 7 and Windows Vista that notifies you when a program tries to run, and asks if you want to continue running it. It's the user's choice if they want to use it. I personally don't use it. It may be disabled on your computer already. Can you post the script you have with ProcessClose()?

Share this post


Link to post
Share on other sites

I trimmed it down to the bare minimum and still no luck. I did have it working briefly with CTRL+SHIFT+d but even that doesn't work now. Here is the minimal version of my script:

HotKeySet("+d", "TestFunc")

Run("C:\Program Files (x86)\metaio\Unifeye Design\Unifeye\Unifeye.exe")
WinWaitActive("Unifeye Design 2.0")
Send("^f")

Func TestFunc()
    MsgBox(0, "TestFunc", "Executed")
EndFunc

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Try this:

#RequireAdmin
HotKeySet("+d", "Terminate")
Global $Process = "Unifeye.exe"

Run("C:\Program Files (x86)\metaio\Unifeye Design\Unifeye\" & $Process) 

WinWaitActive("Unifeye Design 2.0") 
Send("^f")

While 1
WEnd

Func Terminate()    
    If ProcessExists($Process) Then ProcessClose($Process)
    MsgBox(0, "Terminate", $Process & " terminated.")
EndFunc
Edited by darkjohn20

Share this post


Link to post
Share on other sites

Your script ends directly after the windows is detected... is that intentional?

That's a good point. He should have a while loop in there. But maybe he does? He said that was the "bare minimum" of his script.

Share this post


Link to post
Share on other sites

I think I see the problem, my script is completing and exiting before I get a chance to press the "Esc" key, or any key for that matter. Can I tell the script to pause or wait for keyboard input?

Glen

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Look at my example. It will work (now).

Edited by darkjohn20

Share this post


Link to post
Share on other sites

make sure you add a brief sleep in there to avoid the high CPU utilisation.

I was about to but I'm to lazy to add formatting in the AutoIt forum. You can't just press tab like in Scite :idea:.

Share this post


Link to post
Share on other sites

Below is the script I ended up writing. It appears to work as I need it to. Is there anything that is problematic, bad protocol, or taxing on the CPU?

Thanks for the help everybody, I really appreciate it.

Glen

; Script Start - Add your code below here

$SplashImage = "C:\PROJECTS_WINVOLVE\Scenario\splash-4x3.gif"
SplashImageOn("Welcome to the LifePod Zero Gravity Experience", $SplashImage,1280,1024,-1,-1,1)

$file = "C:\PROJECTS_WINVOLVE\Scenario\LifePak15.scef"
Run("C:\Program Files (x86)\metaio\Unifeye Design\Unifeye\Unifeye.exe " & $file)
WinWaitActive("LifePak15 - Unifeye Design 2.0")
Send("^f")
Sleep(10000)
SplashOff()
HotKeySet("{esc}", "captureEsc")
While 1
    Sleep(10000)
WEnd

Func captureEsc()
    ProcessClose("Unifeye.exe")
    Exit
EndFunc

Share this post


Link to post
Share on other sites

You might want a smaller sleep. Sleep(100) would probably work better.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

You might want a smaller sleep. Sleep(100) would probably work better.

Nah not really important in this case as there is no other tasks in the close-loop so any sleep() will work. :idea:

@ianim: Your script looks fine when your intent is to force the program to at least run 10 seconds before the Esc works.

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0