Solved

How to always keep focus on a Win7 app?

Posted on 2014-09-20
9
389 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
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 51

Accepted Solution

by:
Joe Winograd, EE MVE 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 11

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 51

Expert Comment

by:Joe Winograd, EE MVE
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
 
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 11

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 51

Expert Comment

by:Joe Winograd, EE MVE
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 11

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

One of the features I've come to appreciate about Windows 7 and Windows Server 2008 R2 is the ability to pin applications to the task bar. As useful a feature as I've found this, it does have some quirks.  For example, have you ever tried pinning an…
New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now