Jump to content
Sign in to follow this  
sandin

2 scripts with hotkeys can't work at the same time(?)

Recommended Posts

sandin

I have this simple script:

#include <GUIConstants.au3>
HotKeySet("{NUMPAD1}", "_OK_label")
HotKeySet("{NUMPAD0}", "_NOT_OK_label")
$Form1 = GUICreate("Form1", 150, 100, 193, 125)
$Label1 = GUICtrlCreateLabel("Press Num1", 24, 24, 100, 17)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
func _OK_label()
    GUICtrlSetData($Label1, "OK!")
EndFunc
func _NOT_OK_label()
    GUICtrlSetData($Label1, "not ok...")
EndFunc

when I compile it, and start the exe file twice, only one will work and the other won't. Even if I close the working one, the other still won't work, why's that?

Share this post


Link to post
Share on other sites
Monamo

I have this simple script:

#include <GUIConstants.au3>
HotKeySet("{NUMPAD1}", "_OK_label")
HotKeySet("{NUMPAD0}", "_NOT_OK_label")
$Form1 = GUICreate("Form1", 150, 100, 193, 125)
$Label1 = GUICtrlCreateLabel("Press Num1", 24, 24, 100, 17)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
func _OK_label()
    GUICtrlSetData($Label1, "OK!")
EndFunc
func _NOT_OK_label()
    GUICtrlSetData($Label1, "not ok...")
EndFunc

when I compile it, and start the exe file twice, only one will work and the other won't. Even if I close the working one, the other still won't work, why's that?

Give this a shot - It will set enable the hotkeys only for the "active" window:

CODE

#include <GUIConstants.au3>

$Form1 = GUICreate("Form1", 150, 100, 193, 125)

$Label1 = GUICtrlCreateLabel("Press Num1", 24, 24, 100, 17)

Dim $iHotKeysActive = 0

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

_SetHotKeys()

WEnd

Func _OK_label()

GUICtrlSetData($Label1, "OK!")

EndFunc

Func _NOT_OK_label()

GUICtrlSetData($Label1, "not ok...")

EndFunc

Func _SetHotKeys()

If WinActive($Form1) Then

If Not $iHotKeysActive Then

HotKeySet("{NUMPAD1}", "_OK_label")

HotKeySet("{NUMPAD0}", "_NOT_OK_label")

$iHotKeysActive = 1

EndIf

Else

If $iHotKeysActive Then

HotKeySet("{NUMPAD1}")

HotKeySet("{NUMPAD0}")

$iHotKeysActive = 0

EndIf

EndIf

EndFunc


- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Share this post


Link to post
Share on other sites
sandin
someone

Just use _IsPressed()

#include <GUIConstants.au3>
#Include <Misc.au3>

;~ HotKeySet("{NUMPAD1}", "_OK_label")
;~ HotKeySet("{NUMPAD0}", "_NOT_OK_label")

$Form1 = GUICreate("Form1", 150, 100, 193, 125)
$Label1 = GUICtrlCreateLabel("Press Num1", 24, 24, 100, 17)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    If _IsPressed(61) Then _OK_label()
    If _IsPressed(60) Then _NOT_OK_label()
WEnd
func _OK_label()
    GUICtrlSetData($Label1, "OK!")
EndFunc
func _NOT_OK_label()
    GUICtrlSetData($Label1, "not ok...")
EndFunc

Whoops forgot the #Include <Misc.au3>

Edited by someone

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites
sandin

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  

×