kcvinu Posted March 3, 2015 Posted March 3, 2015 (edited) Hi all, I want use more than one key in HotKeySet or _IsPressed functions. This is my code. It is working. But i would like to know if there is any better way to do this. Local $flag1 = False Local $flag2 = False While 1 Sleep(10) if _IsPressed("4D") Then $flag1 = True If _IsPressed("44") Then $flag2 = True if $flag1 = True And $flag2 = True And _IsPressed("41") Then TestSend() WEnd Func TestSend() Send("{BS 3}My Dear Alan{TAB}:{SPACE}") EndFunc ;==>WordSendKeyALT_W Edited March 3, 2015 by kcvinu Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
jaberwacky Posted March 3, 2015 Posted March 3, 2015 (edited) Here's how I'd do it. Your mileage may vary. #include <Misc.au3> Const $ip_m = "4D" Const $ip_d = "44" Const $ip_a = "41" Do If _IsPressed($ip_m) And _IsPressed($ip_d) And _IsPressed($ip_a) Then TestSend() Do Sleep(100) Until Not _IsPressed($ip_m) Or Not _IsPressed($ip_d) Or Not _IsPressed($ip_a) EndIf Sleep(100) Until False Func TestSend() Send("{BS 3}My Dear Alan{TAB}:{SPACE}") EndFunc Edited March 3, 2015 by jaberwacky kcvinu 1 Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
iamtheky Posted March 3, 2015 Posted March 3, 2015 (edited) the OP sets "a" to type that string, everytime, after "m" and "d" have been pressed. So thats probably not desirable without setting those flags back to False after the send, requiring them to be subsequent, or requiring all three to be pressed as in Jab's. Edited March 3, 2015 by boththose kcvinu 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
jaberwacky Posted March 3, 2015 Posted March 3, 2015 the OP sets "a" to type that string, everytime, after "m" and "d" have been pressed. I do not infer that intent from op's code. Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
kcvinu Posted March 3, 2015 Author Posted March 3, 2015 Hi, boththose You are right. jaberwacky's code is not working for me. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
kcvinu Posted March 3, 2015 Author Posted March 3, 2015 Hi jaberwacky, This is my goal => When i pressed 'a' right after 'md', then the text will be 'mda'. Then my script suddenly replaces that 'mda' with 'My dear alan'. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
iamtheky Posted March 3, 2015 Posted March 3, 2015 (edited) not an inference, just stating what that code does differently... Do you want that behavior? because if you start your script in post #1 and type "mom and dad" you will get "mom andMy Dear Alan: " if you want it to work as though it is exploding the abbreviation "mda", you may want to look at hotstrings Edited March 3, 2015 by boththose kcvinu 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
jaberwacky Posted March 3, 2015 Posted March 3, 2015 In that case, Manadar has a hotkey udf which should do what you want. kcvinu 1 Helpful Posts and Websites: AutoIt Wiki | Can't find what you're looking for on the Forum? My scripts: Guiscape | Baroque AU3 Code Formatter | MouseHoverCalltips | SciTe Customization GUI | ActiveWindowTrack Toy | Monitor Configuration UDF
iamtheky Posted March 3, 2015 Posted March 3, 2015 (edited) concur, use manadar's stuff, I edited his example to perform your task expandcollapse popup; Authors: Manadar, GarryFrost ; Contributor: WideBoyDixon #include <WinAPI.au3> #include <WindowsConstants.au3> #include <Array.au3> #include-once Dim $hHook Dim $hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam") Dim $hmod = _WinAPI_GetModuleHandle(0) Dim $hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($hStub_KeyProc), $hmod) Dim $buffer = "" Dim $hotstrings[1] Dim $hotfuncs[1] Dim $hWnd = GUICreate("") GUIRegisterMsg($WM_KEYDOWN, "_GUIKeyProc") ;; ========================== ;; This is your actual script. ;; ========================== ;#include <HotString.au3> HotStringSet("mda","examplefunction") While 1 Sleep(10) WEnd Func examplefunction() Send("{BACKSPACE 3}") Send("My Dear Alan: ") EndFunc ;; ========================== ;; End of actual script. ;; The part above the start of the actual script ;; and below this comment ;; script can be put in another ;; file and included. ;; ========================== Func HotStringSet($hotstring, $func) _ArrayAdd($hotstrings, $hotstring) _ArrayAdd($hotfuncs, $func) EndFunc Func EvaluateKey($keycode) If (($keycode > 64) And ($keycode < 91)) _ ; A - Z Or (($keycode > 47) And ($keycode < 58)) Then ; 0 - 9 $buffer &= Chr($keycode) $buffer = StringRight($buffer, 50) _CheckHotkeys($buffer) EndIf EndFunc ;==>EvaluateKey Func _CheckHotkeys($s) For $i = 0 to UBound($hotstrings)-1 if ( $hotstrings[$i] = StringRight($s, StringLen($hotstrings[$i])) ) Then Call($hotfuncs[$i]) EndIf Next EndFunc Func _GUIKeyProc($hWnd, $Msg, $wParam, $lParam) EvaluateKey(Number($wParam)) EndFunc ;=========================================================== ; callback function. This function must return as quickly as possible or it will stall and block user input ;=========================================================== Func _KeyProc($nCode, $wParam, $lParam) Local $tKEYHOOKS $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndIf If $wParam = $WM_KEYDOWN Then $vkKey = DllStructGetData($tKEYHOOKS, "vkCode") _WinAPI_PostMessage($hWnd, $WM_KEYDOWN, $vkKey, 0) EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc ;==>_KeyProc Func OnAutoItExit() _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hStub_KeyProc) EndFunc ;==>OnAutoItExit Edited March 3, 2015 by boththose kcvinu and jaberwacky 2 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
kcvinu Posted March 3, 2015 Author Posted March 3, 2015 Hi boththose, At the first look, my mind said that "this is the code i am searching for". Becaude, i need to write a script which contains "WM_COMMAND" and SetWindowsHookEx. But i don't know how to use the setwindowshookex function. Anyhow, this should be a great help for me. Thank you very much. But i didn't tested this code yet. I will inform you after that. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
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