Jump to content

Action on key press


gugs
 Share

Go to solution Solved by gugs,

Recommended Posts

Hi All

I am very new to Autoit (I found out about it approximately 5 hours ago) and am pretty much a non-programmer but I need to create a simple script. Essentially i have a task (an e-prime task if any of you are familiar with it) that I want to be able to run.  

Under normal conditions, once the task is completed, the program will normally close by itself  ("terminate") after a certain time period or after a particular key press.  However for my task I need it to close down and re-open to the begin automatically since we are having one person after the other doing the task and we don't want to have to restart the task each time. I also need the option of a keypress response that will allow the staff to close the task down at the end of the day.

For this reason, I programmed it so that the second last screen tells the previous participant that the task has now ended and thank-you for participating, immediately followed, after a wait time for a few seconds, by an "introduction window" that instructs the next participant to press the letter "S" to start the task, or "X" to close the task.  

Throughout the task, the only "acceptable" input keys are the numbers 1-9 and the spacebar - that is until the last screen (the introduction one) where I have programmed it to accept both the S key and X key.  In both cases it will cause the task to terminate.  However I want the autoit script to monitor for the S and X key and either

a.  terminate the autoit script after the X key is pressed and the window has closed because e-prime has already been programmed to handle the termination of the task in response to the letter X, or,

b. wait for the window to close, and then restart the task immediately if the letter s has been pressed.

The reason I came up with the waitwin approach is that even if someone accidentally pressed the letter s or x at any other time during the task, I don't want these key presses to trigger anything in the code or interfere in any way with the running of the task. 

I tried to come up with something but as I said, I really don't know anything about programming so I was hoping someone would be able to look at it and give me feedback. It's not working at the moment but I am not sure exactly why. 

The other questions is that once the e-prime task has closed and re-opened if I press the letter S, will autoit continue to monitor for the letter S/X during this new instance of the task?

I look forward to getting your feedback.

Many thanks!  :thumbsup:

ShellExecute(@DesktopDir & "\Task\Task 2.ebs2")

WinWait("E-Run")

HotKeySet("53", "Restart") 
HotKeySet("58", "Terminate")

While 1   
   Sleep(100)
WEnd
   
Func Restart()
WinWaitClose("E-Run")
ShellExecute(@DesktopDir & "\Task\Task 2.ebs2")
EndFunc
   
Func Terminate()
    Exit
EndFunc
Edited by gugs
Link to comment
Share on other sites

Are you saying this is because I have not referred to the active e-prime window correctly by name? When e-prime runs it's similar to slideshow view in powerpoint.  It takes up the whole screen and I can't see any programs running in the background so I can't read what the name is...Should my code run properly in theory otherwise?  WIll wingettitle solve it?

ShellExecute(@DesktopDir & "\Task\Steve Task 2.ebs2")

WinWait("E-Run")

HotKeySet("53", "Restart") 
HotKeySet("58", "Terminate")

While 1   
   Sleep(100)
WEnd
   
Func Restart()
$title = WinGetTitle("[active]")
WinWaitClose("$title")
ShellExecute(@DesktopDir & "\Task\Steve Task 2.ebs2")
EndFunc
   
Func Terminate()
    Exit
EndFunc
Edited by gugs
Link to comment
Share on other sites

  • Moderators

gugs,

An interesting problem - but we need to know a bit more about the e-prime window (even if it is full-screen it is still a window) to offer more focused help. I quite understand that you want to run the actual task full-screen, but can you run it windowed just for initial testing? That way we can use AutoIt tools to indentify the particular state for which you are looking, i.e. this final screen. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I wasn't able to do anything about it taking over my display so instead I tried to attach a monitor and extend the display so I had the Au3Info.exe running on one side and the task on the other screen.  When I moved my mouse over to the task screen I found the following (see attached screenshot).  However when I changed the code so that the WaitWinClose was ("[DirectDrawDeviceWnd]") it simply exited the program without the shellexecute after clicking on the letter S....I thought I could get around it by trying to return the active window title?

When the task starts, there is a dialogue box that asks you to fill in ID and so on... this is the window that has the title E-Run, not the actual task window. 

Is there a WaitProgramClose command or something similar that could help me get around it (if this is in fact the source of my problem)?

Do you think otherwise the code is doing what I am expecting it to?

L3haoL3.png

Edited by gugs
Link to comment
Share on other sites

  • Moderators

gugs,

It looks as if there is not a lot for AutoIt to recognise in that! :o

I think we might have to go a different way and try to recognise the screen itself. I am not familiar with this e-prime software (other than Googling it earlier) but you say that you have created a screen to ask the user what to do next. Can you alter the colour of a section of this screen so that it can be differentiated from all the others? Such as changing the background colour or the text box? If so, then we could possibly use a Pixel* function to recognise when that particular screen appears. :)

And one point looking at the code you posted above - your HotKeySet syntax is wrong. You need to use the actual key value not the key code, so they should read: ;)

HotKeySet("s", "Restart") 
HotKeySet("x", "Terminate")
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

OK. I think I got this to work using the following code - I think one of the problems holding me back was the use of the numbers in the hotkey. 

ShellExecute(@DesktopDir & "\Task\Steve Task 2.ebs2")

WinWait("E-Run")

HotKeySet("s", "Restart") 
HotKeySet("x", "Terminate")

While 1   
   Sleep(100)
WEnd
   
Func Restart()
$title = WinGetTitle("[active]")
WinWaitClose("$title")
ShellExecute(@DesktopDir & "\Task\Steve Task 2.ebs2")
EndFunc
   
Func Terminate()
    Exit
EndFunc

I have one concern however. If the task terminates in any other way i.e., the participant clicks on the cancel button on the e-prime dialogue box during startup, or they ALT+F4 it, autoit will not know that the task has ended and the script should terminate.  Is there anyway to account for this by making the terminate key - any other situation except for when s key is pressed? 

Link to comment
Share on other sites

OK. I think I got this to work using the following code - I think one of the problems holding me back was the use of the numbers in the hotkey. 

ShellExecute(@DesktopDir & "\Task\Steve Task 2.ebs2")

WinWait("E-Run")

HotKeySet("s", "Restart") 
HotKeySet("x", "Terminate")

While 1   
   Sleep(100)
WEnd
   
Func Restart()
$title = WinGetTitle("[active]")
WinWaitClose("$title")
ShellExecute(@DesktopDir & "\Task\Steve Task 2.ebs2")
EndFunc
   
Func Terminate()
    Exit
EndFunc

I have one concern however. If the task terminates in any other way i.e., the participant clicks on the cancel button on the e-prime dialogue box during startup, or they ALT+F4 it, autoit will not know that the task has ended and the script should terminate.  Is there anyway to account for this by making the terminate key - any other situation except for when s key is pressed? 

 

gugs, welcome!

I hope this helps:

#cs
    1 - I tried to see in the task manager, which process the application "E-Prime" loads when it starts.
    2 - How the tasks are repetitive, the script always kept active until the end of the day.
    Assuming that the process is "notepad.exe":
#ce

#NoTrayIcon
#include <Misc.au3>

AdlibRegister("StartAPP", 15000) ; With intervals of 15 seconds, calls the function checks whether the application is run (prevents cases in which it is closed incorrectly).

;ShellExecute(@DesktopDir & "\Task\Steve Task 2.ebs2") ; Uncomment
ShellExecute("notepad.exe") ; Simulates your application (@DesktopDir & "\Task\Steve Task 2.ebs2")

Local $hDLL = DllOpen("user32.dll")

While 1
    If _IsPressed("53", $hDLL) Then
        Restart()
    EndIf
    If _IsPressed("58", $hDLL) Then
        Terminate()
    EndIf
    Sleep(100)
WEnd

Func Restart()
    ProcessWaitClose("notepad.exe") ; Simulates your process
    Sleep(5000) ; Number of milliseconds to wait
    If Not ProcessExists("notepad.exe") Then
        ;ShellExecute(@DesktopDir & "\Task\Steve Task 2.ebs2") ; Uncomment
        ShellExecute("notepad.exe") ; Simulates your application (@DesktopDir & "\Task\Steve Task 2.ebs2")
        ProcessWait("notepad.exe") ; Simulates your process
    EndIf
EndFunc   ;==>Restart

Func Terminate()
    DllClose($hDLL)
    AdlibUnRegister("StartAPP")
    Exit
EndFunc   ;==>Terminate

Func StartAPP()
    If Not ProcessExists("notepad.exe") Then
        ;ShellExecute(@DesktopDir & "\Task\Steve Task 2.ebs2") ; Uncomment
        ShellExecute("notepad.exe") ; Simulates your application (@DesktopDir & "\Task\Steve Task 2.ebs2")
    EndIf
EndFunc   ;==>StartAPP
Link to comment
Share on other sites

Hi JCEF (and Melba),

Many thanks for your help so far!

Welp! I tried your solution JCEF, replacing notepad.exe with the appropriate process etc.... and it didnt work the way I thought it would (probably my inexperience and confusion).  It opened normally but I found that when I clicked on X on the last screen (which is supposed to allow the program to shut, and terminate the Autoit script, I found instead that 5 instances of the task was trying to open.  

I think I should provide a bit more detail so you both might understand how the task runs etc a bit better.  

The task (Steve Task 2.ebs2) runs using a program called E-Prime.exe (full path C:Program Files (x86)PSTE-Prime 2.0ProgramE-Prime.exe).  This would be analagous to a word document for example, let's call it ABC.doc, running on the program, winword.exe.

When I start up the task Steve Task 2.ebs2, a series of dialogue boxes open up, one after the other, asking the individual a series of questions, such as their age, gender etc.  Each dialogue box a OK button and a Cancel button.  OK causes the next dialogue box to open, and Cancel terminates the task. When the OK button on the last dialogue box is clicked, the task begins.

ntP9sgA.png

 

Once the task is complete, the participant sees a goodbye screen. After 5 seconds, a "Welcome Screen" appears, instructing the next person to either click the letter "S" to begin the task , or the letter "X" to exit the task.  The task would usually be exited for example at the end of the day when the research assistant needs to shut down the computer for example.  

As far as E-Prime is concerned, either key ("S" or "X") will cause the task to terminate.  It is up to Autoit to decide either:

1. Leave the program shut-down and terminate the Autoit script (if the letter X was pressed), waiting for the program to shut down (WinWaitClose), or:

2. Immediately restart the task Steve Task 2.ebs2 (if the letter "S" was pressed), so it almost appears a seamless transition between the "Welcome" screen and the task start-up dialogue box.

I think this is what I have achieved with the following script: 

ShellExecute(@DesktopDir & "\Task\Steve Task 2.ebs2")

WinWait("E-Run")

HotKeySet("s", "Restart") 
HotKeySet("x", "Terminate")

While 1   
   Sleep(100)
WEnd
   
Func Restart()
$title = WinGetTitle("[active]")
WinWaitClose("$title")
ShellExecute(@DesktopDir & "\Task\Steve Task 2.ebs2")
EndFunc
   
Func Terminate()
    Exit
EndFunc

However this script does not account for the fact that Steve Task 2 and E-Prime process can be terminated outside of this "Welcome Screen".  For example, by clicking on the "Cancel" button on the dialogue box, or by bringing up the Windows Task Manager, and ending the E-Prime.exe process.  

In this case, the Autoit script does not know that it should terminate itself, and will try and re-open the Steve Task 2 - which I don't want to happen.  Instead I want it to recognise that the Steve Task 2 task has been closed down,  and to terminate the Autoit script. Essentially the only time it should try to re-open itself and continue to run the script is if the letter S is pressed.  

I think the code has to look something like:

Start Task

Wait for it to load

If the letter s is pressed, wait for the window to close/e-prime exe process to end, then restart it.

If the letter x is pressed, wait for the the window to close/e-prime exe process to end, and then terminate the Autoit script.

Otherwise wait for the the window to close/e-prime exe process to end, and terminate the script (this accounts for the task/program closing by any other method). 

I hope this helps clarify things.....

Edited by gugs
Link to comment
Share on other sites

gugs, I am also beginner. I know it is sometimes difficult to follow the reasoning of others, but this is no problem. What only matters is not giving up. With your problem I am also learning something else.
I think I had misunderstood your initial explanation, so I made some changes.
See if this is close to what you intend:

#NoTrayIcon

Global $Result
Global $MyProcess = "Everything-1.2.1.371.exe"
Global $MyAPP = @ScriptDir & "\Everything-1.2.1.371.exe"
Global $strTextWinFinal = "Everything 1.2.1.371 has been installed on your computer."
; $strTextWinFinal - Esta variável deve ser uma substring do texto da janela final da aplicação (janela final de agradecimento.)
; Deve conter um texto único, que não será encontrado além da janela final.
; $StrTextWinFinal - This variable must be a substring of the text of the final window of the application (the final window of thanks.)
; Must contain a single text, which will not be found beyond the final window.

HotKeySet("x", "Terminate")
HotKeySet("X", "Terminate") ; Beware using 'Shift + x'
HotKeySet("s", "Restart")
HotKeySet("S", "Restart") ; Beware using 'Shift + s'
; If your application also responds to these HotKeys, I think best to use the function '_IsPressed ()' as shown in another script


If Not ProcessExists($MyProcess) Then
    ShellExecute($MyAPP)
EndIf
ProcessWait($MyProcess)

ProcessAPP()

Func ProcessAPP()
    While ProcessExists($MyProcess)
        Local $TextWin = WinGetText("Everything 1.2.1.371 Setup") ; Here you put the TITLE of your final window
        If StringInStr($TextWin, $strTextWinFinal) Then
            $Result = "EndOK" ; You have reached the final window and ended without interruptions
            ProcessWaitClose($MyProcess) ; If it does not close himself, force with: 'If ProcessExists ($ myProcess) Then ProcessClose ($ myProcess)'
        EndIf
        Sleep(100) ; Necessary to avoid overloading the processor
    WEnd
    If $Result = "EndOK" Then ; If is over OK ...
        Sleep(2000) ; ... hold and ...
        ShellExecute($MyAPP) ; ... restart the application: - can be omitted if the application start again alone
        ProcessWait($MyProcess)
        $Result = "" ; empties the variable to restart the application
        ProcessAPP() ; restart
    Else ; Closed application incorrectly
        Exit ; End Autoit
    EndIf
EndFunc   ;==>ProcessAPP

Func Terminate()
    ProcessClose($MyProcess)
    Exit
EndFunc   ;==>Terminate

Func Restart()
    $title = WinGetTitle("[active]")
    If ProcessExists($MyProcess) Then ProcessClose($MyProcess)
    ProcessWaitClose($MyProcess)
    If WinExists($title) Then WinClose($title)
    WinWaitClose($title) ; I think you had an error here
    Sleep(5000)
    If Not ProcessExists($MyProcess) Then
        ShellExecute($MyAPP)
    EndIf
    ProcessWait($MyProcess)
EndFunc   ;==>Restart

I hope this helps

Edited by JCEF
Link to comment
Share on other sites

Hi :)

I tried to run your code but it didn't work the way I anticipated. I ran into a couple of problem. Instead what I thought I would do is create a video which shows you exactly what is going on.  I hope this helps you.  It's almost 2 am here so I hope you understand the accent because I am a little tired and trying to move through it as quickly as possible.  I posted it on youtube, so you should be able to see it shortly.

Link to comment
Share on other sites

Your WinWaitClose statement has the variable inside quotes. Try removing the quotes around the $title variable and see if that works.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

OK So I am not sure how to convert this all into code so I am going to write it into long hand because I think what I need to do is very simple but I just can't achieve the last thing (point 4)...see the video to get a better sense - 

Edited by gugs
Link to comment
Share on other sites

Good night!

I think your video and your last topic were most enlightening.
I do not think you need to look at the windows, but only for the process.

See if it serves your purpose.

;#NoTrayIcon

Global $Result = ""
;Global $MyProcess = "notepad.exe"
;Global $MyAPP = @DesktopDir & "\MyDoc.txt"
Global $MyProcess = "E-Prime.exe"
Global $MyAPP = @DesktopDir & "\Task\Steve Task.ebs2"
Global $Xpress = ""
Global $Spress = ""

HotKeySet("x", "Terminate")
HotKeySet("X", "Terminate") ; Beware using 'Shift + x'
HotKeySet("s", "Restart")
HotKeySet("S", "Restart") ; Beware using 'Shift + s'


If Not ProcessExists($MyProcess) Then
    If FileExists($MyAPP) Then
        ShellExecute($MyAPP)
    Else
        MsgBox(16, "Error:", "Could not find: " & $MyAPP)
        Exit
    EndIf
EndIf

ProcessAPP()

Func ProcessAPP()
    ProcessWait($MyProcess)
    While ProcessExists($MyProcess)
    Sleep(100)
    WEnd
    ProcessAPP_2()
EndFunc   ;==>ProcessAPP

Func ProcessAPP_2()
    If $Xpress = "Xyes" Then
        $Xpress = ""
        Exit
    ElseIf $Spress = "Syes" Then
        $Spress = ""
        If Not ProcessExists($MyProcess) Then
            ShellExecute($MyAPP)
        EndIf
        ProcessAPP()
    Else
        Exit
    EndIf
EndFunc   ;==>ProcessAPP_2

Func Terminate()
    $Xpress = "Xyes"
EndFunc   ;==>Terminate

Func Restart()
    $Spress = "Syes"
EndFunc   ;==>Restart

Hope this helps.

Edited by JCEF
Link to comment
Share on other sites

If the "E-Prime" do not take the command of HotKeys 'S' and 'X' is as the previous script, try this:

;#NoTrayIcon
#include <Misc.au3>

;Global $MyProcess = "notepad.exe"
;Global $MyAPP = @DesktopDir & "\MyDoc.txt"
Global $MyProcess = "E-Prime.exe"
Global $MyAPP = @DesktopDir & "\Task\Steve Task.ebs2"
Global $Kpress = ""
Global $hDLL = DllOpen("user32.dll")

If Not ProcessExists($MyProcess) Then
    If FileExists($MyAPP) Then
        ShellExecute($MyAPP)
    Else
        MsgBox(16, "Error:", "Could not find: " & $MyAPP)
        Exit
    EndIf
EndIf

ProcessAPP()

Func ProcessAPP()
    ProcessWait($MyProcess)
    While ProcessExists($MyProcess)
        Sleep(100)
        If _IsPressed("58", $hDLL) Then
            $Kpress = "Xyes"
        EndIf
        If _IsPressed("53", $hDLL) Then
            $Kpress = "Syes"
        EndIf
    WEnd
    ProcessAPP_2()
EndFunc   ;==>ProcessAPP

Func ProcessAPP_2()
    If $Kpress = "Xyes" Then
        $Kpress = ""
        Exit
    ElseIf $Kpress = "Syes" Then
        $Kpress = ""
        If Not ProcessExists($MyProcess) Then
            ShellExecute($MyAPP)
        EndIf
        ProcessAPP()
    Else
        Exit
    EndIf
EndFunc   ;==>ProcessAPP_2
Edited by JCEF
Link to comment
Share on other sites

  • Solution

Hello!

Thank-you JCEF for your kind help and for persevering with me.... I think I have fixed the problem now. I made one small change to the process app 2 function.  I found that it wouldn't work unless I removed the If Not ProcessExists(.. etc..  I think this is because the while the letters X and S are hotkey for the E-Prime program to quit, the If not process exists would run before the program could actually close.  I tried putting in a ProcessWaitClose in, but it kept on getting an error message. Do you think my change is OK?

Two other small questions:

1. Do you think the first line (If Not ProcessExists($MyProcess) Then) would be sufficient to prevent multiple runnings of the script? The compiled script icon/exe is pretty sensitive and will start up more than once if you accidentally double click on it?

2. I just want to confirm that shift+S is the same thing as if the caps lock is on. and I click s?

Many thanks (again!)

Global $Result = ""
Global $MyProcess = "E-Run.exe"
Global $MyAPP = @DesktopDir & "\The Photon Project\Photon Project Task.ebs2"
Global $Xpress = ""
Global $Spress = ""

Opt("SendCapslockMode", 0)
Send("{CapsLock off}") 

HotKeySet("x", "Terminate")
HotKeySet("X", "Terminate") ; Beware using 'Shift + x'
HotKeySet("s", "Restart")
HotKeySet("S", "Restart") ; Beware using 'Shift + s'


If Not ProcessExists($MyProcess) Then
    If FileExists($MyAPP) Then
        ShellExecute($MyAPP)
    Else
        MsgBox(16, "Error:", "Could not find: " & $MyAPP)
        Exit
    EndIf
EndIf

ProcessAPP()

Func ProcessAPP()
    ProcessWait($MyProcess)
    While ProcessExists($MyProcess)
    Sleep(100)
    WEnd
    ProcessAPP_2()
EndFunc   ;==>ProcessAPP

Func ProcessAPP_2()
    If $Xpress = "Xyes" Then
        $Xpress = ""
        Exit
    ElseIf $Spress = "Syes" Then
        $Spress = ""
        ShellExecute($MyAPP)

        ProcessAPP()
    Else
        Exit
    EndIf
EndFunc   ;==>ProcessAPP_2

Func Terminate()
    $Xpress = "Xyes"
EndFunc   ;==>Terminate

Func Restart()
    $Spress = "Syes"
EndFunc   ;==>Restart
Link to comment
Share on other sites

Hi gugs!

I just put this piece of code: 

If Not ProcessExists($MyProcess) Then
    ShellExecute($MyAPP)
EndIf

because I was not sure if the "E-prime" actually closes and reopens when you press the 's', or simply changed the interface. But now evaluated best (I was a bit tired when I did this work), and it makes no sense its existence because the function "ProcessAPP_2 ()" is only called if the process ceases to exist when performing "ProcessAPP_1 ()". Ie, the "E-prime" actually ends and start again. I think you should also delete this entry "ShellExecute ($ myapp)" because, under normal conditions, the "E-prime" restarts on its own, correct? Try it, because if you start the application with AutoIt and if it has already been initiated by the "E-prime" you end up with multiple instances of the application open.

 

Regarding the next question, I think it's enough that you put this piece of code at the beginning of your script:

#include <Misc.au3>
If _Singleton(@ScriptName, 0) = 0 Then Exit ; If srcipt already compiled

Regarding the last question, in the tests that I did when I was using "Shift + s" or "Shift + x", with the "caps lock" on or off, AutoIt not answer and I do not know why: I do not have much knowledge in AutoIT. I also noticed that using the "HotKeySet ()" the "s" and "x" is not passed to the "notepad", which I used for testing instead of the "E-prime."
For this reason and because using the function "_IsPressed ()" and not the "HotKeySet ()", I checked the hotkeys worked fine on the "notepad" and the AutoIT, I suggested the second version of the script.

Edited by JCEF
Link to comment
Share on other sites

  • 2 weeks later...

Hi gugs!

I just put this piece of code: 

If Not ProcessExists($MyProcess) Then
    ShellExecute($MyAPP)
EndIf

because I was not sure if the "E-prime" actually closes and reopens when you press the 's', or simply changed the interface. But now evaluated best (I was a bit tired when I did this work), and it makes no sense its existence because the function "ProcessAPP_2 ()" is only called if the process ceases to exist when performing "ProcessAPP_1 ()". Ie, the "E-prime" actually ends and start again. I think you should also delete this entry "ShellExecute ($ myapp)" because, under normal conditions, the "E-prime" restarts on its own, correct? Try it, because if you start the application with AutoIt and if it has already been initiated by the "E-prime" you end up with multiple instances of the application open.

 

Regarding the next question, I think it's enough that you put this piece of code at the beginning of your script:

#include <Misc.au3>
If _Singleton(@ScriptName, 0) = 0 Then Exit ; If srcipt already compiled

Regarding the last question, in the tests that I did when I was using "Shift + s" or "Shift + x", with the "caps lock" on or off, AutoIt not answer and I do not know why: I do not have much knowledge in AutoIT. I also noticed that using the "HotKeySet ()" the "s" and "x" is not passed to the "notepad", which I used for testing instead of the "E-prime."

For this reason and because using the function "_IsPressed ()" and not the "HotKeySet ()", I checked the hotkeys worked fine on the "notepad" and the AutoIT, I suggested the second version of the script.

Now you were right the first time - the e-prime will close but will not re-open itself when EITHER the letter s or x is pressed.  The current code stops multiple instances of e-prime from opening. Clicking on the exe file will cause multiple scripts to run, but after the first one they cannot open mutiple instances of e-prime because the first one is already open.  All the instances of the script will then close when the original e-prime screen closes.  As you also said, adding in the singleton code can also stop multiple instances of the script running.

Many thanks for all of your help! I need to work out the caps lock thing but it is not super urgent as the other issues! 

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...