Solved

How to always keep focus on a Win7 app?

Posted on 2014-09-20
9
412 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 52

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 52

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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
l2tp tunnel from pc to router 14 74
Windows 7s template 4 39
Upgrade from Win7 Premium to Pro? 3 20
Dell Precision 5510 Downgrade to Windows 7 Pro 5 28
I recently purchased an HP EliteBook 2540p notebook/laptop. It has two video ports on it – VGA and DisplayPort. HP offers an optional docking station for the 2540p that also has both a VGA port and a DisplayPort. There are numerous online reports do…
You may have a outside contractor who comes in once a week or seasonal to do some work in your office but you only want to give him access to the programs and files he needs and keep privet all other documents and programs, can you do this on a loca…
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

920 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

11 Experts available now in Live!

Get 1:1 Help Now