James Posted February 14, 2008 Share Posted February 14, 2008 Hi, Don't you find it really annoying when you accidentally press the insert button and end up typing over all that work you just spent hours on? Well, I was trying to fix that exact problem! I made this program which beeps if you press the Insert button. There is a tray options which allows you to turn on or off the program. However, I can turn it on but not off. I have spent 30 mins working on this and can't work out why... expandcollapse popup#include <Constants.au3> Opt("TrayMenuMode",1) ; 45 = Insert Global $_IPack = "icons.icl", $Yup = False TraySetIcon($_IPack, 9); 9 = Red Off | 7 = Green On $TurnOn = TrayCreateItem("Turn ITK On") $TurnOff = TrayCreateItem("Turn ITK Off") TrayCreateItem("") ; $Settings = TrayCreateItem("Settings") $About = TrayCreateItem("About ITK") $Exit = TrayCreateItem("Exit") TraySetState() While 1 $msg = TrayGetMsg() Select Case $msg = $TurnOff ITK(0) Case $msg = $TurnOn ITK(1) Case $msg = 0 ContinueLoop Case $msg = $Exit $Yup = False If $Yup = False Then ExitLoop EndSelect WEnd Func ITK($io_switch) Select Case $io_switch = 0 TraySetIcon($_IPack, 9) $Yup = False Case $io_switch = 1 TraySetIcon($_IPack, 7) $Yup = True While $Yup = True Do If _IsPressed(Hex("45")) Then Beep(500) Until $Yup = False WEnd Case Else MsgBox(32, @ScriptName, "Invalid command parameter!") EndSelect EndFunc Func _IsPressed($sHexKey, $vDLL = 'user32.dll') Local $a_R = DllCall($vDLL, "int", "GetAsyncKeyState", "int", '0x' & $sHexKey) If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1 Return 0 EndFunc ;==>_IsPressed I know it is that While Loop but I cannot break it! Thanks, James Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Swift Posted February 14, 2008 Share Posted February 14, 2008 (edited) Set the loop like this Global $Active = 0 to turn the loop on type $Active = 1 While $active blah... blah... WENd to stop it...put anywhere: $Active = 0 Does that help? So like this: expandcollapse popup#include <Constants.au3> Global $Active = 1 Opt("TrayMenuMode",1) ; 45 = Insert Global $_IPack = "icons.icl", $Yup = False TraySetIcon($_IPack, 9); 9 = Red Off | 7 = Green On $TurnOn = TrayCreateItem("Turn ITK On") $TurnOff = TrayCreateItem("Turn ITK Off") TrayCreateItem("") ; $Settings = TrayCreateItem("Settings") $About = TrayCreateItem("About ITK") $Exit = TrayCreateItem("Exit") TraySetState() While $active $msg = TrayGetMsg() Select Case $msg = $TurnOff $active = 0 Case $msg = $TurnOn $active = 1 Case $msg = 0 ContinueLoop Case $msg = $Exit $Yup = False If $Yup = False Then ExitLoop EndSelect WEnd Func ITK($io_switch) Select Case $io_switch = 0 TraySetIcon($_IPack, 9) $Yup = False Case $io_switch = 1 TraySetIcon($_IPack, 7) $Yup = True While $Yup = True Do If _IsPressed(Hex("45")) Then Beep(500) Until $Yup = False WEnd Case Else MsgBox(32, @ScriptName, "Invalid command parameter!") EndSelect EndFunc Func _IsPressed($sHexKey, $vDLL = 'user32.dll') Local $a_R = DllCall($vDLL, "int", "GetAsyncKeyState", "int", '0x' & $sHexKey) If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1 Return 0 EndFunc;==>_IsPressed at myself...got the wrong idea...so you wanna stop the ITK() loop? Hmm...Make a While/Wend loop and use the While $Active and $Active = 0 and $Active = 1! that may help...I'll check in to it now... Wow james...you have stumped me on this one! Edited February 14, 2008 by Swift Link to comment Share on other sites More sharing options...
James Posted February 14, 2008 Author Share Posted February 14, 2008 Nope. Same... Nothing. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
weaponx Posted February 14, 2008 Share Posted February 14, 2008 I'm not sure what you are having this problem with but if its Word, I would disable the feature entirely.http://www.tech-recipes.com/microsoft_word_tips1069.htmlBetter yet, disable the Insert key altogether:http://www.wikihow.com/Disable-the-Insert-Key-in-Windows Link to comment Share on other sites More sharing options...
James Posted February 14, 2008 Author Share Posted February 14, 2008 weaponx, I like to see myself do it Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
weaponx Posted February 14, 2008 Share Posted February 14, 2008 weaponx, I like to see myself do it A bit narcissistic? Reminds me of a certain scene from American Psycho... Link to comment Share on other sites More sharing options...
James Posted February 14, 2008 Author Share Posted February 14, 2008 Lol. Not like that Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
weaponx Posted February 14, 2008 Share Posted February 14, 2008 Here is whats happening:You click "Turn ITK On" which sends the script into the Do...Until loop. Permanently. There is no way to break out of the loop because the TrayGetMsg() isn't running while stuck in said loop. You should switch to TrayOnEventMode. Link to comment Share on other sites More sharing options...
James Posted February 14, 2008 Author Share Posted February 14, 2008 I tried this: expandcollapse popup#include <Constants.au3> Opt("TrayMenuMode", 1) ; 45 = Insert Opt("TrayOnEventMode",1) Global $_IPack = "icons.icl", $Yup = 0 TraySetIcon($_IPack, 9); 9 = Red Off | 7 = Green On $TurnOn = TrayCreateItem("Turn ITK On") TrayItemSetOnEvent(-1,"TrayOn") $TurnOff = TrayCreateItem("Turn ITK Off") TrayItemSetOnEvent(-1,"TrayOff") TrayCreateItem("") ; $Settings = TrayCreateItem("Settings") ;$About = TrayCreateItem("About ITK") $Exit = TrayCreateItem("Exit") TrayItemSetOnEvent(-1,"MyExit") TraySetState() While 1 Sleep(100) WEnd Func ITK($io_switch) Select Case $io_switch = 0 $Yup = 0 TraySetIcon($_IPack, 9) Case $io_switch = 1 TraySetIcon($_IPack, 7) $Yup = 1 While $Yup If _IsPressed(Hex("45")) Then Beep(500) WEnd Case Else MsgBox(32, @ScriptName, "Invalid command parameter!") EndSelect EndFunc ;==>ITK Func _IsPressed($sHexKey, $vDLL = 'user32.dll') Local $a_R = DllCall($vDLL, "int", "GetAsyncKeyState", "int", '0x' & $sHexKey) If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1 Return 0 EndFunc ;==>_IsPressed Func TrayOff() ITK(0) EndFunc Func TrayOn() ITK(1) EndFunc Func MyExit() Exit EndFunc Doesn't work though Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
James Posted February 15, 2008 Author Share Posted February 15, 2008 Any idea why it doesn't work. I have the same effect as before. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
mads3n Posted February 15, 2008 Share Posted February 15, 2008 Hi, Don't you find it really annoying when you accidentally press the insert button and end up typing over all that work you just spent hours on? Well, I was trying to fix that exact problem! I made this program which beeps if you press the Insert button. There is a tray options which allows you to turn on or off the program. However, I can turn it on but not off. I have spent 30 mins working on this and can't work out why... James If _IsPressed(Hex("45")) Then Beep(500,100) $yup = 0 endif ? Mads3n.dk Link to comment Share on other sites More sharing options...
James Posted February 15, 2008 Author Share Posted February 15, 2008 (edited) Nothing there. No beep, however I can I turn ITK off and exit! Woops: expandcollapse popup#include <Constants.au3> Opt("TrayMenuMode", 1) ; 45 = Insert Opt("TrayOnEventMode", 1) Global $_IPack = "icons.icl", $Yup = 0 TraySetIcon($_IPack, 9); 9 = Red Off | 7 = Green On $TurnOn = TrayCreateItem("Turn ITK On") TrayItemSetOnEvent(-1, "TrayOn") $TurnOff = TrayCreateItem("Turn ITK Off") TrayItemSetOnEvent(-1, "TrayOff") TrayCreateItem("") ; $Settings = TrayCreateItem("Settings") $About = TrayCreateItem("About ITK") TrayItemSetOnEvent(-1, "About") $Exit = TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "MyExit") TraySetState() While 1 Sleep(100) WEnd Func ITK($io_switch) Select Case $io_switch = 0 $Yup = 0 TraySetIcon($_IPack, 9) Case $io_switch = 1 TraySetIcon($_IPack, 7) $Yup = 1 While $Yup = 1 If _IsPressed(Hex("45")) Then Beep(500) $Yup = 0 EndIf WEnd Case Else MsgBox(32, @ScriptName, "Invalid command parameter!") EndSelect EndFunc ;==>ITK Func _IsPressed($sHexKey, $vDLL = 'user32.dll') Local $a_R = DllCall($vDLL, "int", "GetAsyncKeyState", "int", '0x' & $sHexKey) If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1 Return 0 EndFunc ;==>_IsPressed Func TrayOff() ITK(0) EndFunc ;==>TrayOff Func TrayOn() ITK(1) EndFunc ;==>TrayOn Func MyExit() Exit EndFunc ;==>MyExit Func About() MsgBox(0, "Insert Hotkey", "ITK is a product of James-Brooks.net Copyright 2008.") EndFunc ;==>About No, that only works once. Edited February 15, 2008 by JamesB Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
mads3n Posted February 15, 2008 Share Posted February 15, 2008 (edited) strange.. the script seems to work fine here aah.. wait a sec, it doesnt.. i see.. ill see what i can do edit: how about this: expandcollapse popup#include <Constants.au3> Opt("TrayMenuMode",1) ; 45 = Insert Global $_IPack = "icons.icl", $Yup = False TraySetIcon($_IPack, 9); 9 = Red Off | 7 = Green On $TurnOn = TrayCreateItem("Turn ITK On") $TurnOff = TrayCreateItem("Turn ITK Off") TrayCreateItem("") ; $Settings = TrayCreateItem("Settings") $About = TrayCreateItem("About ITK") $Exit = TrayCreateItem("Exit") TraySetState() While 1 $msg = TrayGetMsg() Select Case $msg = $TurnOn TraySetIcon($_IPack, 7) $Yup = True While $Yup = True If _IsPressed(Hex("45")) Then Beep(500,50) $msg = TrayGetMsg() Select Case $msg = $TurnOff ExitLoop Case $msg = $Exit $Yup = False If $Yup = False Then Exit EndSelect WEnd Case $msg = 0 ContinueLoop Case $msg = $Exit $Yup = False If $Yup = False Then Exit EndSelect WEnd Func _IsPressed($sHexKey, $vDLL = 'user32.dll') Local $a_R = DllCall($vDLL, "int", "GetAsyncKeyState", "int", '0x' & $sHexKey) If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1 Return 0 EndFunc ;==>_IsPressed Edited February 15, 2008 by mads3n Mads3n.dk Link to comment Share on other sites More sharing options...
James Posted February 15, 2008 Author Share Posted February 15, 2008 (edited) Thanks! I just need to make it change the icon back! Thanks! Edited February 15, 2008 by JamesB Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Innovative Posted February 15, 2008 Share Posted February 15, 2008 Seriously, i loled at this $Yup = False Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now