Solved

How to always keep focus on a Win7 app?

Posted on 2014-09-20
9
535 Views
Last Modified: 2014-10-05
The customer runs a simple app on his Win7 Pro PC out in the warehouse.  It just sits there waiting for data from barcode scanners and scales.  Everything is fine until it loses focus now and then.  Usually we can't see anything causing this, so my guess is that it is something going on in Windows or in another app, "behind the scenes", but still somehow taking the focus off the app they are trying to run.

I have removed a few things that came with the computer that might normally pop up and ask questions.  Literally nothing is still activated in msconfig.  They ARE running Norton Internet Security, but like I say, I have never seen it--or anything else--up on the screen when this happens, so I don't know what is causing the loss of focus.

It is a big deal for them, because when this happens, their scan and weight data is not going to the app, and if they don't see this happening on the screen, the data is lost.  So I wonder if there is some type of Windows setting that will always insure that the warehouse app keeps focus, no matter what else might be going on in the background.  Or, is there some other way to solve this annoying problem?  TIA
0
Comment
Question by:sasllc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 54

Accepted Solution

by:
Joe Winograd, EE MVE 2015&2016 earned 400 total points
ID: 40334573
I don't know why it is losing focus, but here's a way to make it keep focus. First, download and install the excellent (and free!) programming/scripting language called AutoHotkey. Here's an EE article that shows where/how to download and install it:
http://www.experts-exchange.com/Web_Development/Document_Imaging/A_13315-How-to-Combine-Merge-PDF-Files-in-Many-Subfolders.html

The article is about a different topic — you may safely ignore most of it — use it just for the instructions on downloading and installing AutoHotkey.

When AutoHotkey is installed, it will own the file type AHK. Now create a plain text file (with file type AHK, not TXT) with this code (or simply download the file that I attached):
SetTitleMatchMode,2
Loop
{
  WinActivate,WinTitle ; title is case sensitive
  Sleep,1000 ; wait one second (time is specified in milliseconds)
}

Open in new window

This will loop forever (with a one-second wait in between) looking for the name of the program in the title bar — replace WinTitle in the WinActivate command with whatever appears in the title of their barcode app (the title is case sensitive). Note that there are three choices for the SetTitleMatchMode value:

1 - A window's title must start with the specified WinTitle to be a match.
2 - A window's title can contain WinTitle anywhere inside it to be a match.
3 - A window's title must exactly match WinTitle to be a match.

The code above has 2 (CONTAINS) - change it to whatever you want. Btw, everything after a semi-colon is a comment.

Put a shortcut to the AHK file in the Startup group. For your convenience, I attached the script in an AHK file called <KeepFocus.ahk>. Use any text editor (such as Notepad) to modify it to have the SetTitleMatchMode and WinTitle values that your customer needs.

If you ever want to exit the script (which loops forever), simply right-click the AutoHotkey "H" icon in the system tray/notification area (blue arrow below) and select Exit from the context menu (red arrow below):

Exit AutoHotkey script
Regards, Joe
0
 
LVL 12

Expert Comment

by:zalazar
ID: 40334581
Can you maybe check what is the value of ForegroundLockTimeout by opening a Registry Editor via:
Start |Run... |regedit
and lookup the value of:
HKEY_CURRENT_USER\Control Panel\Desktop\ForegroundLockTimeout
0
 
LVL 54

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40334610
Hi zalazar,

> this is more a workaround than solving the problem

Yes, it is. As I stated in my opening sentence, I don't know why it is losing focus, so my approach is, indeed, a work-around.

> You can probably accomplish the same with a visual basic script

"You" (or someone else) can — I can't. :)  I know little about VBScript.

> As it's a customer environment it might not be allowed to install extra software.

Maybe, maybe not. They already have a warehouse app, so obviously some extra software is allowed.

> I would prefer a background program which continuously checks or listens if the top/activated window has changed and only then activate back the application window.

If that's what you prefer, I suggest you write it — and in VBScript, if that's your language of choice.

All I've done here is provide a very simple solution that I'm confident will work, but there certainly may be better solutions. Regards, Joe

P.S. @zalazar, I see that you deleted your comment while I was working on the reply offline in my text editor. How come?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 50

Expert Comment

by:jcimarron
ID: 40334630
sasllc --
What program is taking away the focus?
Has the "simple app " just lost focus and is still running in the background or is it closed (shut down)?
0
 
LVL 12

Expert Comment

by:zalazar
ID: 40334652
Hi Joe,
Thank you very much for your comments.

> this is more a workaround than solving the problem
#Yes, it is. As I stated in my opening sentence, I don't know why it is losing focus, so my approach is, indeed, a work-around.
Ok

> You can probably accomplish the same with a visual basic script
#"You" (or someone else) can — I can't. :)  I know little about VBScript.
Thanks for the explanation.
I just wrote a small VBScript but noticed that the AppActivate method is not giving the desired effect.

> As it's a customer environment it might not be allowed to install extra software.
#Maybe, maybe not. They already have a warehouse app, so obviously some extra software is allowed.
Ok

>I would prefer a background program which continuously checks or listens if the top/activated window has changed and only then activate back the application window.
#If that's what you prefer, I suggest you write it — and in VBScript, if that's your language of choice.
I do prefer this although it's probably not possible to do that with VBScript and it would require a real programming language like Visual Basic .NET.

>P.S. @zalazar, I see that you deleted your comment while I was working on the reply offline in my text editor. How come?
#I was not completely satisfied with my comments and was just rephrasing it because of the VBScript comment and looking at some other options.
I'm sorry about that.
Thanks again.
0
 
LVL 3

Author Comment

by:sasllc
ID: 40334662
Jcimmaron,
I dont know why or how it is losing focus, but it does continue to run on the screen. If I click the top of the window, then it comes back into focus, running properly, collecting data. Just like any other program in Windows that loses focus. The problem is that I don't know why it loses it, nor how to make it never lose it.
0
 
LVL 50

Expert Comment

by:jcimarron
ID: 40334676
sasllc ----
So  you are saying the "simple app" is not losing focus to another window (and no other app is running behind it), but rather the "simple app" just becomes semi -inactive?
0
 
LVL 54

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
ID: 40334698
> small VBScript but noticed that the AppActivate method is not giving the desired effect

Hmmm, very interesting! Knowing little about VBScript, I can't help with that. I can say that AutoHotkey's WinActivate command has always worked well for me, and numerous EE members have been happy with it when I recommended it. Here are just three recent examples (there are more in the past) where it worked for folks:

http://www.experts-exchange.com/Programming/Misc/Q_28486055.html
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Windows/Windows_7/Q_28517572.html
http://www.experts-exchange.com/Programming/Languages/Scripting/Q_28519544.html

In sasllc's current situation, I realize that this attacks the symptom, not the root cause of the problem. But he says it is a big deal for the customer, resulting in losing scan and weight data, so if I were in his shoes, I'd be tempted to put on this band-aid (which I'm confident will work) while I continued to look for the real underlying cause followed by the real cure for it. But, hey, that's just me. :)  Regards, Joe
0
 
LVL 12

Assisted Solution

by:zalazar
zalazar earned 100 total points
ID: 40334725
I have also worked with AutoHotkey and it's indeed a good program.

@sasllc:
Focusing on the root cause, you might try the following to identify the "faulty" program.
Download Process Monitor from the Microsoft Sysinternals website:
http://technet.microsoft.com/en-us/sysinternals/bb896645

Unpack the zip file and copy Procmon.exe and procmon.chm to the hard disk of the local computer.
E.g. to C:\Temp
Start Procmon.exe

From the icons below the "Menu" only select/enable "Show Process and Thread Activity".
So unselect Registry, File and Network activity.
Minimize the Process Monitor window and activate the application window and wait for the problem to occur and hopefully it will not take too long before it happens.
By looking at processes/threads which are created you might identify the program which does give the problem.

You might also post a list here of all installed software from "Control Panel"/Programs so we could try to identify which program or background process is causing this.
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question