Vicate Posted January 26, 2012 Share Posted January 26, 2012 (edited) Greetings, What I am trying to do is very simple: Map one key (such as "S") to another (such as "NUMPAD5")... however I cannot find a more simple way to achieve than this: If (_IsPressed('53', $dll)) Then Send ( "{NUMPAD5 DOWN}") EndIf If Not (_IsPressed('53', $dll)) Then Send ( "{NUMPAD5 UP}") EndIf This works but there has got to be a less redundant way to do this. HotKeySet seems to only work with functions, otherwise it would be amazingly simple! Anyway, any help would be appreciated. Thanks! Edit: It seems the send commands are being continually sent which is compromising the efficiency of the script. I could add a $Num5 = 'Down'/ 'Up' to only send when it it pressed or not, but again, is there a less redundant way of achieving this? Edited January 26, 2012 by Vicate Link to comment Share on other sites More sharing options...
Exit Posted January 26, 2012 Share Posted January 26, 2012 HotKeySet("s", "_s") Func _S() Send("{NUMPAD5}") EndFunc ;==>_S While 1 Sleep(9999999) WEnd App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Blinky Posted January 27, 2012 Share Posted January 27, 2012 (edited) this is a combined script from yours and forumer100`s #include <Misc.au3> HotKeySet("{s}", "_s") While 1 Sleep(10) WEnd Func _s() If _IsPressed('53')=1 Then Send ( "{NUMPAD5 DOWN}") Do Sleep(10) Until _IsPressed('53')=0 Send ( "{NUMPAD5 UP}") EndFunc edit: sorry copied the while loop from forumer100 edit 2: @AdmiralAlkex yep thx for the input Edited January 28, 2012 by Blinky Link to comment Share on other sites More sharing options...
somdcomputerguy Posted January 27, 2012 Share Posted January 27, 2012 Replace Sleep(9999999) with Sleep(10), otherwise it'll be awhile before the function gets executed. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted January 28, 2012 Share Posted January 28, 2012 Replace Sleep(9999999) with Sleep(10), otherwise it'll be awhile before the function gets executed.No it won't. HotKeySet() is an interrupting function. 10 ms or 10 minutes won't make a difference in that main-loop.On the other hand, 9999999 is really long and odd. Should be changed anyway. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
somdcomputerguy Posted January 28, 2012 Share Posted January 28, 2012 Ah. Thanks for clarifying. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Exit Posted January 28, 2012 Share Posted January 28, 2012 "On the other hand, 9999999 is really long and odd. Should be changed anyway."It is not long and odd.Maximum sleep time is 2147483647 milliseconds (24 days). From the help file.Since the script has no other purpose than mapping the key, the higher the value, the less CPU usage.2147483647 would be the best value, but I was too lasy to type this value. 9999999 seemed enough to me.If there would be any other code in this script, the while loop would be obsolete. App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 28, 2012 Moderators Share Posted January 28, 2012 forumer100,You might be interested to know that we did some testing a while ago and found that pausing the script for some 100 nanoseconds was quite sufficient to keep the CPU load and temperature down, so using Sleep(10) to give a 10 millisecond pause should be quite enough. There is nothing wrong with using a higher value as long as you have nothing else in the loop and you are using OnEvent mode - but it is not a habit I would encourage as it is too likely to cause problems when one of those 2 conditions is not met. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Exit Posted January 28, 2012 Share Posted January 28, 2012 You might be interested to know that we did some testing a while ago and found that pausing the script for some 100 nanoseconds was quite sufficient to keep the CPU load and temperature down, so using Sleep(10) to give a 10 millisecond pause should be quite enough. So I did some testing just now to prove that there is a difference in using sleeptime 10 or 9999999 Let run this script and see the diiference in runtime between those two values. #NoTrayIcon If Not @Compiled Then Exit MsgBox(262144, "", @LF & "Please compile the script." & @LF, 0) If $CmdLine[0] Then ; this is a subtask While 1 Sleep($CmdLine[1]) WEnd EndIf $text = "" $text &= _sleeptimetest(300, 10) ; 300 tasks, 10 milliseconds sleeptime $text &= _sleeptimetest(300, 9999999) ; 300 tasks, 9999999 milliseconds sleeptime MsgBox(262144, "Sleeptimetest results", @LF & $text & @LF, 0) Func _sleeptimetest($taskcount, $sleeptime) $timer = TimerInit() For $i = 1 To $taskcount ; build all subtasks ShellExecute(@ScriptFullPath, $sleeptime) Next $aPid = ProcessList(@ScriptName) For $i = 1 To $aPid[0][0] If $aPid[$i][1] = @AutoItPID Then ContinueLoop ProcessClose($aPid[$i][1]) Next Return TimerDiff($timer) & " " & $taskcount & " " & $sleeptime & @LF EndFunc ;==>_sleeptimetest On my PC, the results are: 27 seconds.for sleeptime 10, 21 seconds.for sleeptime 9999999. This is caused by the excessive timing interupts when usimg small sleeptimes. If you have a fast performing PC, try it with a taskcount of 1000 and you will see a great difference. There are many eventdriven sample script in this forum, with have the following lines as last lines of the main script: while 1 sleep(10) wend Since there is no chance to leave this loop, it is the best solution to enter a high sleeptime. Then there will be no timed interupt disturbing the other processes. The eventdriven functions (hotkeys and tray) will run asyncroniosly. not waiting for the sleep() to expire. On the other hand, when not using eventdriven mode. you will never use a neverending loop like above. App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 28, 2012 Moderators Share Posted January 28, 2012 forumer100, My comments above were based on CPU loading not timing, but your results are very interesting and worth keeping in mind. Thank you for taking the time to do the research and also letting us know about it. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted February 2, 2012 Share Posted February 2, 2012 @forumer100You can't argue that 9 is a odd number.On my PC, the results are:27 seconds.for sleeptime 10,21 seconds.for sleeptime 9999999I'm not sure those results can be trusted.I got:6491.93972473025 300 106274.87610812973 300 9999999And the results fluctuate wildly. I run it a few times and got both better and worse.Upping the taskcount to 511 (apparantly max ProcessList() can handle) didn't significantly change anything.31286.8068539954 511 1027493.0119172682 511 9999999That was from yesterday. Today I get results like:20405.9340395888 511 1019211.1125300205 511 9999999And17706.6637471937 511 1017225.6584927448 511 9999999A 10 second difference. Nothing was changed. In fact, I didn't turn my PC off tonight, it's still running from when I got the earlier numbers.But to be serious again, look at this:16534.902058108 511 1015244.8923780673 511 100014864.3502235083 511 1000014905.5738240136 511 6000014669.8804963747 511 10000014716.847366782 511 99999991 second is enough to take away half the "advantage" from 9999999, and at 10 seconds it's practically gone.Some funny runs:17396.5232570957 511 1018299.180720395 511 999999916958.8375397638 511 1017366.7506567308 511 100017772.9488343291 511 1000017655.7055918348 511 6000017622.4985949785 511 10000017912.3853921139 511 9999999TL;DR: 9999999 looks fugly and provide little to no benefits. This test you have written is very inconsistent. Your PC is slooow. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface 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