Sign in to follow this  
Followers 0
lordicast

Pause Hotkeys?(Sloved) thanks all

14 posts in this topic

#1 ·  Posted (edited)

Im working on a script that has hotkeys and when i minimize the the program or im working on another window the hotkeys are still active is there anyway to halt the hotkeys when the program is not being used.

I used

While 1 
     if winactive("The Program") then
        Hotkeyset("{enter}")
     endif
Wend

And as a func

Global $Pause
Func init()
  $pause = NOT $Pause
  While $Pause
    Sleep(100)
   Wend
endfunc

And read tutorial for a couple of hours with no success. according to autoit help files if the script is paused then the hotkeys shouldnt work, but they do. Please help

Edited by lordicast

[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Maybe something like this:

While 1
    $state = WinGetState("The Program")
    If BitAnd($state, 8) Then
        Hotkeyset("{enter}", "MyFunc")
    Else
        Hotkeyset("{enter}")
    EndIf
Sleep(100)
WEnd

Note: I just briefly tested this code.

Edited by Prab

Share this post


Link to post
Share on other sites

Im working on a script that has hotkeys and when i minimize the the program or im working on another window the hotkeys are still active is there anyway to halt the hotkeys when the program is not being used.

I used

While 1 
     if winactive("The Program") then
        Hotkeyset("{enter}")
     endif
Wend

And as a func

Global $Pause
Func init()
  $pause = NOT $Pause
  While $Pause
    Sleep(100)
   Wend
endfunc

And read tutorial for a couple of hours with no success. according to autoit help files if the script is paused then the hotkeys shouldnt work, but they do. Please help

Best way is to use GUISetAccelerators then other windows won't be affected.

But if you use a hot key then in the function called by the hot key you need to do something like this

$ThisGui = GuiCreate("This Gui Title",......
HotKeySet("{F10}","F10called")

Func F10called()
 if WinGetTitle("") <> "This Gui Title" then
  HotKeySet("{F10}")
  Send("{F10}")
  Return
 EndIf

;rest of function

endfunc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Found another way that might be easier to understand:

If WinGetTitle("[active]") = "The Program" Then
    Hotkeyset("{enter}", "MyFunc")
EndIf
While 1
    WinWaitNotActive("The Program")
    Hotkeyset("{enter}")
    WinWaitActive("The Program")
    Hotkeyset("{enter}", "MyFunc")
WEnd

Share this post


Link to post
Share on other sites

Best way is to use GUISetAccelerators then other windows won't be affected.

But if you use a hot key then in the function called by the hot key you need to do something like this

$ThisGui = GuiCreate("This Gui Title",......
HotKeySet("{F10}","F10called")

Func F10called()
 if WinGetTitle("") <> "This Gui Title" then
  HotKeySet("{F10}")
  Send("{F10}")
  Return
 EndIf

;rest of function

endfunc
I havent heard of GUISetAccelerators? UDF? i tried this in my while and it didnt work

while 1
     if WinGetTitle("") <> "This Gui Title" then
      HotKeySet("{enter}","all")
  Return
 EndIf
wend

[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites

Search for GUISetAccelerators in the help file. It is a standard function.

Your code never disables the hotkey. To disable the hotkey use the line:

HotKeySet("{enter}")

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This doesnt work either

while 1
     if WinGetTitle("") <> "This Gui Title" then
      HotKeySet("{enter}","all")
    Else
      Hotkeyset("{enter}")
      EndIf
wend

BTW GUISetAccelerators is nowhere in the help file i think i got a older version Scite4Autoit3 Version 1.71

Edited by lordicast

[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites

This doesnt work either

while 1
     if WinGetTitle("") <> "This Gui Title" then
      HotKeySet("{enter}","all")
                 Else
                  Hotkeyset("{enter}")
                  EndIf
wend

BTW GUISetAccelerators is nowhere in the help file i think i got a older version Scite4Autoit3 Version 1.71

You make it difficult for people to help you. To me your posts are like taking your wheels to a garage and complaining that the engine won't turn them round :)

Is the title of your Gui really "This Gui "Title"?

Can you show a complete sample script which has the problem?


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Your code seems to work (for me) but is also seems backwards. When the window is active the hotkey does NOT run. When the window is not active the hotkey DOES run. Also I am assuming you have a function called "all", right?

Edit: My version of Scite4Autoit3 is 1.76. You might want to upgrade.

Edited by Prab

Share this post


Link to post
Share on other sites

You make it difficult for people to help you. To me your posts are like taking your wheels to a garage and complaining that the engine won't turn them round :)

Is the title of your Gui really "This Gui "Title"?

Can you show a complete sample script which has the problem?

Ok its gonna take a while script is 4 page scripts long. i got to make a short version ill post it in 5 min or so.


[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Ok so here is a script that close to what im doin lets say i type note i want it to open note pad and minimize the gui and stop the hotkey enter. it does all that except stop the hot keys. i want to type on the notepad and be able to hit enter to go down a line and so on please help. thanks martin

#include <GUIConstants.au3>
#include <Guiedit.au3>
HotKeySet("{F3}","calls")
$gui1 = GUICreate("trouble",664,453,193,449)
$ed = GUICtrlCreateEdit("",0,0,663,449)
GUICtrlSetData(-1,"Commands>")
GUISetState (@SW_SHOW)    
GUISetState(@SW_MAXIMIZE)
Global $sLastLine = _GUICtrlEdit_GetTextLen($ed)
Global $pau

While 1
    sleep(10)
    _GUICtrlEdit_SetSel($ed,_Guictrledit_gettextlen($ed)+1,_guictrledit_gettextlen($ed)+1)
     if WinGetTitle("") = "trouble" then
      HotKeySet("{enter}","all")
    Else
      Hotkeyset("{enter}")
      EndIf
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

Func Calls()
    $pau = NOT $Pau
    GUISetState(@SW_SHOW)
    While $Pau
        GUISetState(@SW_MINIMIZE)
    WEnd
EndFunc

Func all()
    Local $sCmd = StringMid(guictrlread($ed),$sLastline+1)
    _GUICtrlEdit_BeginUpdate($ed)
    _GUICtrlEdit_EndUpdate($ed)
    Global $sLastline = _guictrledit_gettextlen($ed)
    if $sCmd = 'note' Then
        Run('notepad.exe')
        Calls()
    Else
        NoCom()
    EndIf
EndFunc

Func NoCom()
    _GUICtrlEdit_AppendText($ed,@CRLF&"no valid")
    _GUICtrlEdit_AppendText($ed,@CRLF&"Commands>")
    Global $sLastline = _guictrledit_gettextlen($ed)
EndFunc
Edited by lordicast

[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites

Looks to me like you just need to do what I told you in my earlier post where I gave this example

$ThisGui = GuiCreate("This Gui Title",......

HotKeySet("{F10}","F10called")

Func F10called()

if WinGetTitle("") <> "This Gui Title" then

HotKeySet("{F10}")

Send("{F10}")

Return

EndIf

;rest of function

endfunc

CODE

#include <GUIConstants.au3>

#include <Guiedit.au3>

HotKeySet("{F3}", "Calls")

$gui1 = GUICreate("trouble", 664, 453, 193, 449)

$ed = GUICtrlCreateEdit("", 0, 0, 663, 449)

GUICtrlSetData(-1, "Commands>")

GUISetState(@SW_SHOW)

GUISetState(@SW_MAXIMIZE)

Global $sLastLine = _GUICtrlEdit_GetTextLen($ed)

Global $pau

HotKeySet("{enter}","all")

While 1

Sleep(10)

_GUICtrlEdit_SetSel($ed, _GUICtrlEdit_GetTextLen($ed) + 1, _GUICtrlEdit_GetTextLen($ed) + 1)

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

Func Calls()

;$pau = Not $pau

;GUISetState(@SW_SHOW)

;While $pau

GUISetState(@SW_MINIMIZE)

while processexists("notepad.exe")

sleep(500)

WEnd

GUISetState(@SW_RESTORE)

;WEnd

EndFunc ;==>Calls

Func all()

If WinGetTitle("") <> "trouble" Then

HotKeySet("{enter}")

Send("{Enter}")

HotKeySet("{enter}", "all")

Return

EndIf

Local $sCmd = StringMid(GUICtrlRead($ed), $sLastLine + 1)

_GUICtrlEdit_BeginUpdate($ed)

_GUICtrlEdit_EndUpdate($ed)

Global $sLastLine = _GUICtrlEdit_GetTextLen($ed)

If $sCmd = 'note' Then

Run('notepad.exe')

Calls()

Else

NoCom()

EndIf

EndFunc ;==>all

Func NoCom()

_GUICtrlEdit_AppendText($ed, @CRLF & "no valid")

_GUICtrlEdit_AppendText($ed, @CRLF & "Commands>")

Global $sLastLine = _GUICtrlEdit_GetTextLen($ed)

EndFunc ;==>NoCom


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Looks to me like you just need to do what I told you in my earlier post where I gave this example

problem with that is i was using f3 as a toggle between hiding the program itself and stoping the hotkeys and when i hit f3 again i want it to appear. so i can continue doing what i was doing. also it would take way to long to keep adding

while processexists(".exe")
because im not using it for just notepad i got about 200 commands and i want it to halt hotkeys when they are active.

[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites

:) Nevermind i got it.

#include <GUIConstants.au3>
#include <Guiedit.au3>
HotKeySet("{F3}","calls")
$gui1 = GUICreate("trouble",664,453,193,449)
$ed = GUICtrlCreateEdit("",0,0,663,449)
GUICtrlSetData(-1,"Commands>")
GUISetState (@SW_SHOW)    
GUISetState(@SW_MAXIMIZE)
Global $sLastLine = _GUICtrlEdit_GetTextLen($ed)
Global $pau

While 1
    sleep(10)
    _GUICtrlEdit_SetSel($ed,_Guictrledit_gettextlen($ed)+1,_guictrledit_gettextlen($ed)+1)
    HotKeySet("{enter}","all")
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend

Func Calls()
    $pau = NOT $Pau
    GUISetState(@SW_SHOW)
    While $Pau
        GUISetState(@SW_HIDE)
        HotKeySet("{enter}")
    WEnd
EndFunc

Func all()
    Local $sCmd = StringMid(guictrlread($ed),$sLastline+1)
    _GUICtrlEdit_BeginUpdate($ed)
    _GUICtrlEdit_EndUpdate($ed)
    Global $sLastline = _guictrledit_gettextlen($ed)
    if $sCmd = 'note' Then
        Run('notepad.exe')
        Calls()
    Else
        NoCom()
    EndIf
EndFunc

Func NoCom()
    _GUICtrlEdit_AppendText($ed,@CRLF&"no valid")
    _GUICtrlEdit_AppendText($ed,@CRLF&"Commands>")
    Global $sLastline = _guictrledit_gettextlen($ed)
EndFunc

[Cheeky]Comment[/Cheeky]

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