How do you have a script run in the background?
Posted 30 June 2011 - 02:07 PM
Posted 30 June 2011 - 02:10 PM
Posted 30 June 2011 - 02:17 PM
Posted 30 June 2011 - 02:54 PM
1. Instead of HotKeySet, use _IsPressed in a loop. To avoid spamming the function, make it wait until the key is released, before returning. (There are other options to avoid the spamming if you want to function to return right away.)
2. At the start of a function, disable the HotKeySet that called it, then use Send() to send the keys and set the hotkey again.
Posted 30 June 2011 - 03:08 PM
Basically, after i runt the script, i just want to be able to continue with my regular computer activities..but everytime i press "A" or "a", the beep should occur
Instead...the script takes over and the only way to send the keypress to other programs, like word or office, is to exit out of the script
Posted 30 June 2011 - 03:22 PM
Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.
Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.
_FileGetProperty - Retrieve the properties of a file SciTE Toolbar - A toolbar demo for use with the SciTE editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.
GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips. Latin Square password generator
Posted 30 June 2011 - 03:26 PM
Posted 30 June 2011 - 03:34 PM
question is...how does the _IsPressed function work? and why is the length of the hexidecimal ? and why does he put $i from 1 to 121?
I'm still very new to programming...obviously lol...
Posted 30 June 2011 - 03:56 PM
_IspressedEx is a modified version of _IsPressed, that only calls a function once for each keypress, much like HotKeySet. You can replace those lines with _IsPressed() if you want to see the difference.
_IsPressed and _IsPressedEx both use a hex code to determine what key is pressed. (values can be found in the helpfile for _IsPressed). The script you posted just checks pretty much every key and would result in a whole lot of beeping.
You don't need to know much about DLL's to use these functions. Just open it before the function is called and close it when you exit. _IsPressed will even open and close the DLL automatically if you don't supply a handle, but that slows things down, so I left it out of my function.
#NoTrayIcon Global $aKeyStillPressed ;used to keep track of keystates Global $dll = DllOpen("user32.dll") ;Open the dll used in _IsPressedEx While 1 If _IsPressedEx('1b', $dll) Then stopscript() ;These lines replace the hotkeyset and have to be in a the main loop If _IsPressedEx('41', $dll) Then beeper() ;Captures both a and A. Check states of capslock and shipt if you need to know what was pressed. Sleep(10) ;important to avoid cpu usage! WEnd Func stopscript() DllClose($dll) ;Tidy up after yourself! Exit EndFunc Func beeper() Beep(2000, 500) EndFunc Func _IsPressedEx($hexKey, $u32dll) Local $iKey = Dec($hexKey) If $iKey > 255 Or $iKey < 0 Then Return SetError(1,0,0) Local $aR = DllCall($u32dll, "int", "GetAsyncKeyState", "int",'0x' & $hexKey) If @error Then Return SetError(2,0,0) If $aKeyStillPressed[$iKey] Then ;If the key was already registered as pressed If BitAND($aR, 0x8000) <> 0x8000 Then $aKeyStillPressed[$iKey] = False ;Check if it is still pressed and update if needed Return 0 ;do nothing ElseIf BitAND($aR, 0x8000) = 0x8000 Then ;If the key wasn't registered as pressed, but is pressed now it must be a new keypress $aKeyStillPressed[$iKey] = True ;Update the pressed status Return 1 EndIf Return 0 EndFunc
Posted 30 June 2011 - 04:07 PM
just a quick learning question though...
where are you entering true or false values for the $aKeyStillPressed array?
i can see it checks for a true or false here
but i cannot see where the array is modified in anyway
Posted 30 June 2011 - 05:40 PM
You don't really need to do anything with the array though, unless you want to set timer that allows the key to start repeating if it's pressed for long enough.
Posted 30 June 2011 - 07:11 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users