Sign in to follow this  
Followers 0
matrixnz

Forcing Window Keyboard Focus

10 posts in this topic

Hi there

I have two questions I'm hoping someone can help me with.

The scenario: I have two windows, one that requires Keyboard Focus and the other Mouse Focus i.e. for scrolling a map in a web page using Java (no keyboard required) The Windows are on Separate Screens (i.e. Dual Monitors)

1. Is it possible to have a Window with Keyboard Focus and the other with Mouse Focus and if so could someone help me with the code?

Alternatively

2. I'd like to keep the Window that requires Keyboard Focus Active and Always on Top so I wrote the script below which basically forces the particular window to "Enable - Always on top" and "Always Active" and it works however when I select the "Disable - Always on Top" it won't work unless I kill the Window session, I know it's due to the "While WinExists ("Untitled - Notepad") = 1" statement but I couldn't figure out how to keep the Window Focused without getting it to loop the $radio1. Can anyone help with my code?

Cheers

#Include <Constants.au3>

#NoTrayIcon

Opt("TrayMenuMode",1)

$radio1 = TrayCreateItem("Enable - Always on Top", -1, -1, 1)

TrayItemSetState(-1, $TRAY_CHECKED)

$radio2 = TrayCreateItem("Disable - Always on Top", -1, -1, 1)

TrayCreateItem("")

$exititem = TrayCreateItem("Exit")

TraySetState()

While 1

$msg = TrayGetMsg()

Select

Case $msg = $radio1

While WinExists ("Untitled - Notepad") = 1

WinActivate("Untitled - Notepad")

WinSetOnTop("Untitled - Notepad", "", 1)

WEnd

Case $msg = $radio2

WinSetOnTop("Untitled - Notepad", "", 0)

Case $msg = $exititem

ExitLoop

EndSelect

WEnd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)

$radio1 = TrayCreateItem("Enable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$radio2 = TrayCreateItem("Disable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")

TraySetState()

While 1
$msg = TrayGetMsg()
Select

Case $msg = $radio1
If WinExists ("Untitled - Notepad") Then
WinActivate("Untitled - Notepad")
WinSetOnTop("Untitled - Notepad", "", 1)
Else
    Sleep(100)
    EndIf

Case $msg = $radio2
WinSetOnTop("Untitled - Notepad", "", 0)

Case $msg = $exititem
ExitLoop

EndSelect
WEnd

When you have a notepad open, click on the icon, click on enable. Also, disable works now. Not sure if this is what you wanted exactly. If you need some more help post back.

Edited by Sardith

[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Share this post


Link to post
Share on other sites

Thanks Sardith for the quick reply, is it possible for it to continue looping so that the Window is always active? Although the Window stays on top, it loses focus if I click on another Window for example.

Cheers

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)

$radio1 = TrayCreateItem("Enable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$radio2 = TrayCreateItem("Disable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")

TraySetState()

While 1
$msg = TrayGetMsg()
Select

Case $msg = $radio1
If WinExists ("Untitled - Notepad") Then
WinActivate("Untitled - Notepad")
WinSetOnTop("Untitled - Notepad", "", 1)
Else
    Sleep(100)
    EndIf

Case $msg = $radio2
WinSetOnTop("Untitled - Notepad", "", 0)

Case $msg = $exititem
ExitLoop

EndSelect
WEnd

When you have a notepad open, click on the icon, click on enable. Also, disable works now. Not sure if this is what you wanted exactly. If you need some more help post back.

Share this post


Link to post
Share on other sites

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)


$radio1 = TrayCreateItem("Enable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$radio2 = TrayCreateItem("Disable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()

While 1
$msg = TrayGetMsg()
Select

Case $msg = $radio1
TrayItemSetState($radio2, $TRAY_UNCHECKED)
WinActivate("Untitled - Notepad", "")
WinSetOnTop("Untitled - Notepad", "", 1)

Case $msg = $radio2
TrayItemSetState($radio1, $TRAY_UNCHECKED)
AdlibDisable()
WinSetOnTop("Untitled - Notepad", "", 0)

Case $msg = $exititem
Exit

EndSelect
WEnd

Corrected some things in my last post. Like uncheck system, that wasn't in place etc.


[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Share this post


Link to post
Share on other sites

Thanks again, however still the same problem the window won't stay Active if I click another window.

Is it possible to use something like

While msg = $radio1

....

So that it continues to loop so that the Window stays active until they either select "Disable - Always on Top" or select Exit.

Cheers

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
$radio1 = TrayCreateItem("Enable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$radio2 = TrayCreateItem("Disable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()

While 1
$msg = TrayGetMsg()
Select

Case $msg = $radio1
TrayItemSetState($radio2, $TRAY_UNCHECKED)
WinActivate("Untitled - Notepad", "")
WinSetOnTop("Untitled - Notepad", "", 1)

Case $msg = $radio2
TrayItemSetState($radio1, $TRAY_UNCHECKED)
AdlibDisable()
WinSetOnTop("Untitled - Notepad", "", 0)

Case $msg = $exititem
Exit

EndSelect
WEnd

Corrected some things in my last post. Like uncheck system, that wasn't in place etc.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
$radio1 = TrayCreateItem("Enable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$radio2 = TrayCreateItem("Disable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()

While 1
$msg = TrayGetMsg()
Select

Case $msg = 0
    If WinExists("Untitled - Notepad", "") Then
        WinActivate("Untitled - Notepad", "")
EndIf
    
Case $msg = $radio1
TrayItemSetState($radio2, $TRAY_UNCHECKED)
WinActivate("Untitled - Notepad", "")
WinSetOnTop("Untitled - Notepad", "", 1)


Case $msg = $radio2
TrayItemSetState($radio1, $TRAY_UNCHECKED)
AdlibDisable()
WinSetOnTop("Untitled - Notepad", "", 0)

Case $msg = $exititem
Exit

EndSelect
WEnd

Off topic:

(Sorry had to eat) This does what you want I think.

Edited by Sardith

[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Share this post


Link to post
Share on other sites

Sorry for the delay needed sleep, we seemed to of gone in a loop :) This works similar to my first piece of code where selecting disable doesn't work.

Cheers

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)
$radio1 = TrayCreateItem("Enable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$radio2 = TrayCreateItem("Disable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()

While 1
$msg = TrayGetMsg()
Select

Case $msg = 0
    If WinExists("Untitled - Notepad", "") Then
        WinActivate("Untitled - Notepad", "")
EndIf
    
Case $msg = $radio1
TrayItemSetState($radio2, $TRAY_UNCHECKED)
WinActivate("Untitled - Notepad", "")
WinSetOnTop("Untitled - Notepad", "", 1)
Case $msg = $radio2
TrayItemSetState($radio1, $TRAY_UNCHECKED)
AdlibDisable()
WinSetOnTop("Untitled - Notepad", "", 0)

Case $msg = $exititem
Exit

EndSelect
WEnd

Off topic:

(Sorry had to eat) This does what you want I think.

Share this post


Link to post
Share on other sites

#Include <Constants.au3>
#NoTrayIcon

Global $Enabled = 0

Opt("TrayMenuMode",1)
$radio1 = TrayCreateItem("Enable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$radio2 = TrayCreateItem("Disable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()

While 1
$msg = TrayGetMsg()
Select

Case $msg = 0 and $Enabled = 1
    If WinExists("Untitled - Notepad", "") Then
        WinActivate("Untitled - Notepad", "")
EndIf
   
Case $msg = $radio1
TrayItemSetState($radio2, $TRAY_UNCHECKED)
WinActivate("Untitled - Notepad", "")
WinSetOnTop("Untitled - Notepad", "", 1)
$Enabled = 1

Case $msg = $radio2
TrayItemSetState($radio1, $TRAY_UNCHECKED)
AdlibDisable()
WinSetOnTop("Untitled - Notepad", "", 0)
$Enabled = 0

Case $msg = $exititem
Exit

EndSelect
WEnd

Didn't give you the most up to date version.


[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Share this post


Link to post
Share on other sites

Hi Sardith

Works like a charm, appreciate your time and effort, I'll spend some time analysing the code to see how you got it to work.

Thanks again.

Cheers

#Include <Constants.au3>
#NoTrayIcon

Global $Enabled = 0

Opt("TrayMenuMode",1)
$radio1 = TrayCreateItem("Enable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$radio2 = TrayCreateItem("Disable - Always on Top", -1, -1, 1)
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()

While 1
$msg = TrayGetMsg()
Select

Case $msg = 0 and $Enabled = 1
    If WinExists("Untitled - Notepad", "") Then
        WinActivate("Untitled - Notepad", "")
EndIf
   
Case $msg = $radio1
TrayItemSetState($radio2, $TRAY_UNCHECKED)
WinActivate("Untitled - Notepad", "")
WinSetOnTop("Untitled - Notepad", "", 1)
$Enabled = 1

Case $msg = $radio2
TrayItemSetState($radio1, $TRAY_UNCHECKED)
AdlibDisable()
WinSetOnTop("Untitled - Notepad", "", 0)
$Enabled = 0

Case $msg = $exititem
Exit

EndSelect
WEnd

Didn't give you the most up to date version.

Share this post


Link to post
Share on other sites

Pm me or make a topic if you need anymore help.

Never said anything.. But, Welcome to the Autoit Forums =).

Take care.


[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

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