Sign in to follow this  
Followers 0
AutID

Script doesn't work while not focused

13 posts in this topic

Hello,

I have a problem here. I had a small script for some keystrokes so I could make my life easier with my computer
It was a small code I was using everyday on my laptop. Today I moved it on my computer so my wife could use it and it is not working

The script is a piece of code more or less with some _IsPressed functions which it check if a keystroke is pressed and sends some other keys depends on the setting.
I used to run it and it would work wherever my focus was(Internet Explorer, some clients, other programs) on my laptop

Now that I moved it on my computer it is not working. It runs normally but as soon as scite looses focus it doesn't work. When scite get focus it works like a charm.
Any idea why this happen.

Thanks in advance.


 

Share this post


Link to post
Share on other sites



do you want educated guesses or better some help ? then you should post your script.


[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

Do you even know _IsPressed function?

In case you don't here you go:

#include <Misc.au3>

Local $hDLL = DllOpen("user32.dll")
 
While (True)
If _IsPressed("45", $hDLL) Then
Send("{S 30}") 
EndIf
WEnd

This doesn't work on my computer, it works on my laptop though.

 

I remember having some similar problems with control functions on clients which they would work on my laptop but not on my computer.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

AutID,

That is not safe code to run. Is that the same code that you let your wife use?

As for the control functions, If the windows to be automated are run as admin then your script needs to be run as admin to interact with them. It may vary depending on OS and settings used. That is my best guess of the issue.

Edit:

Reason I state unsafe code as Send() can send to anything that is active. Be it something done accidental that may do damage. If you have some safe guards then good. But I remind others to be aware of the risk if testing the code displayed.

Edited by MHz

Share this post


Link to post
Share on other sites

Reason I state unsafe code as Send() can send to anything that is active. Be it something done accidental that may do damage. If you have some safe guards then good. But I remind others to be aware of the risk if testing the code displayed.

 

Not to mention the tight loop that has got to be killing the processor... 


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I have tested this similar code numerous times. It seems to work as expected. Tested on Windows 7 x64. AutoIt 3.3.8.1 run as x32 and x64.

#include <Misc.au3>
Global $hDLL = DllOpen("user32.dll")

MsgBox(0, @ScriptName, 'Begin test with using "e" as Hotkey')

ShellExecute('notepad')
If @error Then Exit 1
WinWait('[CLASS:Notepad]', '', 5)

While (True)
    If Not WinExists('[CLASS:Notepad]') Then
        ExitLoop
    ElseIf WinActive('[CLASS:Notepad]') And _IsPressed("45", $hDLL) Then
        Send("{S 30}")
    EndIf
    Sleep(10)
WEnd

DllClose($hDLL)

MsgBox(0x40000, @ScriptName, 'End of test')

I also tried to set Shift Lock on manually to see if I could fail the hotkey but the hotkey still worked and sent the data. I tried ShellExecute with the runas verb and hotkey still worked and sent the data.

A 3rd party hotkey program or a certain application could possibly upset the Hotkey by chance. That would be outside the control of AutoIt if it happens. Though I would not expect "e" to be used by 3rd party programs to cause issue but could be still possible. There is also the S 30 times is something to look at as something may be intercepting that. I know you do not use the hotkey S in your script that could foul up the operation but another application may be using it for something or blocking it.

Edited by MHz

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I tried this out to see if it would work with my idea of using ControlSend.  It doesn't.  Isn't Notepad just one big edit control?  Also the helpfile says that ControlSend will work on a window/control.  I used the id of the edit control which is 15.  Any ideas?

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites

jaberwock6669,

ControlSend works for me. Replace Send("{S 30}") with ControlSend("[CLASS:Notepad]", "", "Edit1", "{S 30}") to test.

Notepad is a big edit control with window borders, yes. That is layman terms.

Share this post


Link to post
Share on other sites

AutID,

That is not safe code to run. Is that the same code that you let your wife use?

As for the control functions, If the windows to be automated are run as admin then your script needs to be run as admin to interact with them. It may vary depending on OS and settings used. That is my best guess of the issue.

Edit:

Reason I state unsafe code as Send() can send to anything that is active. Be it something done accidental that may do damage. If you have some safe guards then good. But I remind others to be aware of the risk if testing the code displayed.

I mentioned that an client that was running from an executer was actually running as admin. That's why it wasn't working. My bad not seeing it.

As for the my script, no it's not that above. I am using controlsend so I can avoid other problems.

The problem I am having atm is that the script will be an while/wend loop with 10 if statements for 10 keystrokes.

If _IsPressed Then ....etc etc etc

Is there an other way to do it without all these 10 if statements? I think if the current script will run for like 10 mins it will get heavy and after 15 won't be working anymore.

 

Share this post


Link to post
Share on other sites

I mentioned that an client that was running from an executer was actually running as admin. That's why it wasn't working. My bad not seeing it.

As for the my script, no it's not that above. I am using controlsend so I can avoid other problems.

The problem I am having atm is that the script will be an while/wend loop with 10 if statements for 10 keystrokes.

If _IsPressed Then ....etc etc etc

Is there an other way to do it without all these 10 if statements? I think if the current script will run for like 10 mins it will get heavy and after 15 won't be working anymore.

 

Ok I gave a solution to this. The bad thing is that I had to create a keylogger so I could check every keystroke pressed and I know such things are not much welcome here. Anyway thanks to MHz for the answer to my first question ;)

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