standardUser54 Posted February 2, 2021 Share Posted February 2, 2021 I'm trying to make something that will accept 2 inputs from a user (hotkey, text). I've gotten everything to work except for the part of assigning the hotkeys and making all of them work simultaneously. Currently it accepts and creates the hotkeys, however will only use the values from the last saved input. I understand (at least I think) what is going wrong, I'm just unsure of how I can fix it. I'm self taught so apologies if I am just looking right over a simple solution The issue as I see it, is my $hotkey and $text variables are simply holding the last value assigned to them. What I need it to do is send the text associated with the key pressed. in this example pressing a, s, or d all result in msgbox with hello, rather then pressing a and returning fuu. $hotkey = "" ;user input here, but initializing a few random .ini info IniWrite("file.ini", "1", "Key", "a") IniWrite("file.ini", "1", "text", "fuu") IniWrite("file.ini", "2", "Key", "s") IniWrite("file.ini", "2", "text", "bar") IniWrite("file.ini", "3", "Key", "d") IniWrite("file.ini", "3", "text", "hello") global $aSecNames = IniReadSectionNames("file.ini") For $i = 1 to $aSecNames[0] $hotkey = IniRead("file.ini", $aSecNames[$i], "Key", "") HotKeySet($hotkey, "_test") Global $text = IniRead("file.ini", $aSecNames[$i], "text", "") Next While 1 WEnd Func _test() ;send($text) MsgBox(0, "",$text) EndFunc Thanks for any assistance Link to comment Share on other sites More sharing options...
Dan_555 Posted February 2, 2021 Share Posted February 2, 2021 (edited) See the Autoit Help for HotKeySet, the "Example 2, @HotKeyPressed usage" Quote $text variables are simply holding the last value assigned to them. Yes, a variable which is assigned in a loop, gets overwritten by each loop. You can use an array or the above suggestion instead. Edited February 2, 2021 by Dan_555 standardUser54 1 Some of my script sourcecode Link to comment Share on other sites More sharing options...
standardUser54 Posted February 2, 2021 Author Share Posted February 2, 2021 That was it, thank you Dan. Quite a simple solution after all this time ahah. Here is my hackjob solution for any who might stumble across this. $hotkey = "" ;user input here, but initializing random .ini info IniWrite("file.ini", "1", "Key", "a") IniWrite("file.ini", "1", "text", "fuu") IniWrite("file.ini", "2", "Key", "s") IniWrite("file.ini", "2", "text", "bar") IniWrite("file.ini", "3", "Key", "d") IniWrite("file.ini", "3", "text", "hello") global $aSecNames = IniReadSectionNames("file.ini") For $i = 1 to $aSecNames[0] $hotkey = IniRead("file.ini", $aSecNames[$i], "Key", "") HotKeySet($hotkey, "_test") Next While 1 WEnd Func _test() ;loop through all sections while and compare key value to the @hotkeypressed value For $i = 1 to $aSecNames[0] if IniRead("file.ini", $aSecNames[$i], "Key", "") = @HotKeyPressed Then $text = IniRead("file.ini", $aSecNames[$i], "text", "") EndIf Next MsgBox(0, "",$text) EndFunc Dan_555 1 Link to comment Share on other sites More sharing options...
JockoDundee Posted February 2, 2021 Share Posted February 2, 2021 (edited) Unless you’re deflecting bullets in real-time, you might want to put a sleep(10) (or longer) in your loop While 1 Sleep(10) WEnd Your CPU will thank you... Edited February 2, 2021 by JockoDundee standardUser54 and seadoggie01 1 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Nine Posted February 3, 2021 Share Posted February 3, 2021 Since all hotkeys must be unique, you could streamline your ini file and (likewise) your code this way : #include <Constants.au3> #include <Array.au3> ;user input here, but initializing random .ini info IniWrite("file.ini", "HotKeys", "a", "fuu") IniWrite("file.ini", "HotKeys", "s", "bar") IniWrite("file.ini", "HotKeys", "d", "hello") Global $aHotKeys = IniReadSection("file.ini", "HotKeys") For $i = 1 to $aHotKeys[0][0] HotKeySet($aHotKeys[$i][0], _Test) Next While Sleep (100) WEnd Func _Test() Local $iInd = _ArraySearch($aHotKeys, @HotKeyPressed, 1, Default, 1, 2, Default, 0) If @error Then Exit MsgBox ($MB_SYSTEMMODAL, "", "Error on hotkey search") ConsoleWrite ($aHotKeys[$iInd][1] & @CRLF) EndFunc standardUser54 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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