ibecko Posted February 1, 2023 Share Posted February 1, 2023 hi, how I can globaly fix non declared variable issue when I run function from HotKeySet() ? HotKeySet('{ESC}', 'function_test') function_test() function_test('blablabla') Func function_test($var='') If IsDeclared('var') then ConsoleWrite("when this function run like function_test() or function_test('var test') from code work fine, $var is declared, $var='"&$var&"', now press ESC"&@CRLF&@CRLF) If Not IsDeclared('var') then ConsoleWrite("when this function run pressing key from HotKeySet() $var not declred and script exit with error 'Variable used without being declared.'"&@CRLF&@CRLF) If Not IsDeclared('var') then ConsoleWrite("$var='"&$var&"'"&@CRLF&@CRLF) EndFunc While True Sleep(20) WEnd I know, its possible to add firt line on function where I check if variable is declared and if no declare it but why? I declare variable on function parameter and it works for scripts but no for HotKeySet thanks Link to comment Share on other sites More sharing options...
Solution Danp2 Posted February 1, 2023 Solution Share Posted February 1, 2023 From the help file -- Quote The called function can not be given parameters. They will be ignored. You could use a 2nd function in the HotKeySet that calls the original function. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
ibecko Posted February 1, 2023 Author Share Posted February 1, 2023 no, I dont wanna call any function parameter from hotkeyset, try my code and press ESC my question is: Func function_test($var='') has local declared $var variable (only for this function) and why hotkeyset ignore this declaration I must check declaration and redeclare $var again, then works fine, but this is duplicate declaration of local variable HotKeySet('{ESC}', 'function_test') function_test() function_test('blablabla') Func function_test($var='') If Not IsDeclared('var') then $var='' If IsDeclared('var') then ConsoleWrite("when this function run like function_test() or function_test('var test') from code work fine, $var is declared, $var='"&$var&"', now press ESC"&@CRLF&@CRLF) If Not IsDeclared('var') then ConsoleWrite("when this function run pressing key from HotKeySet() $var not declred and script exit with error 'Variable used without being declared.'"&@CRLF&@CRLF) If Not IsDeclared('var') then ConsoleWrite("$var='"&$var&"'"&@CRLF&@CRLF) EndFunc While True Sleep(20) WEnd Link to comment Share on other sites More sharing options...
ioa747 Posted February 1, 2023 Share Posted February 1, 2023 25 minutes ago, Danp2 said: You could use a 2nd function in the HotKeySet that calls the original function. try this way HotKeySet('{ESC}', 'function_ESC') function_test() function_test('blablabla') Func function_test($var='') If Not IsDeclared('var') then $var='' If IsDeclared('var') then ConsoleWrite("when this function run like function_test() or function_test('var test') from code work fine, $var is declared, $var='"&$var&"', now press ESC"&@CRLF&@CRLF) If Not IsDeclared('var') then ConsoleWrite("when this function run pressing key from HotKeySet() $var not declred and script exit with error 'Variable used without being declared.'"&@CRLF&@CRLF) If Not IsDeclared('var') then ConsoleWrite("$var='"&$var&"'"&@CRLF&@CRLF) EndFunc Func function_ESC() function_test('blablabla') EndFunc While True Sleep(20) WEnd I know that I know nothing Link to comment Share on other sites More sharing options...
ibecko Posted February 2, 2023 Author Share Posted February 2, 2023 ok, now I understand, hotkeyset can't read variable declared as parameter... best way is checking and declaring all variables, thanks Link to comment Share on other sites More sharing options...
ioa747 Posted February 2, 2023 Share Posted February 2, 2023 (edited) https://www.autoitscript.com/autoit3/docs/functions/HotKeySet.htm The called function ( from HotKeySet ) can not be given parameters. They will be ignored. that's why You should use a 2nd function in the HotKeySet that calls the original function. Edited February 2, 2023 by ioa747 I know that I know nothing 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