Jump to content

Intersecting ESC


Recommended Posts

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

Link to comment
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.

Link to comment
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

Link to comment
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()?

Link to comment
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
Link to comment
Share on other sites

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
Link to comment
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

Link to comment
Share on other sites

  • Developers

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

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...