Morthawt Posted April 21, 2012 Share Posted April 21, 2012 Hi. I am in still coding on my version of what you could call a string hotkey system and am looking for a better yet still relatively simple way to detect the current key pressed on the keyboard that is less cpu intensive. Let me explain how I am currently doing it. Currently I have a list of all alpha-numeric keys in a 2 dimensional array, first has the hex key and the second has the description. I do a loop that checks _ispressed against all the entries in all of the array entries each time it cycles through. Is there a way I can pull the raw hex code or something for what ever happens to be the current key press so that I can reduce the cpu usage of my script? Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
kylomas Posted April 21, 2012 Share Posted April 21, 2012 Morthawt, I know that this was mentioned in your last post on this subject. Look at "hotstring". I don't remember where it is, do a search for it. In particular, look at the way the hook passes the key value back to the caller. I believe that using this method (post message) eliminates the whole timing issue (looping fast enough to catch all keys but not so fast that you dominate the CPU). kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Morthawt Posted April 21, 2012 Author Share Posted April 21, 2012 I will check thanks Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
Morthawt Posted April 21, 2012 Author Share Posted April 21, 2012 I am looking at the source for it but I don't seem to be able to find what to canibalise to get the ability to just detect what ever is the current pressed key ? Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
kylomas Posted April 21, 2012 Share Posted April 21, 2012 Morthawt, Are you familiar with "hooking" procedures? Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted April 21, 2012 Share Posted April 21, 2012 Nevermind. The key value is passed to "_Guikeyproc" which calls "evaluatekey". Do you see that? Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Morthawt Posted April 21, 2012 Author Share Posted April 21, 2012 (edited) Morthawt,Are you familiar with "hooking" procedures?lol absolutely not in the least. I don't get that deep into windows and its atomic structure. I just go with the flow using what I know and learn the best way I can. So far I have made my script totally functional and taken steps to minimize cpu usage but I would like to improve it by still being to check for the strings at any time without needing a control key to start watching all alpha-numeric keys.If I can find a relatively simple way just to get the current key press from windows, I could just use that information every 100 ms or something rather than having to go checking through the entire alphabet and two different sets of numbers in that same amount of time. Edited April 21, 2012 by Morthawt Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
Morthawt Posted April 21, 2012 Author Share Posted April 21, 2012 Nevermind. The key value is passed to "_Guikeyproc" which calls "evaluatekey".Do you see that?So what would I need to take? I was looking at the _Guikeyproc area but I saw a variable in the middle of that dll call and could not figure it out. From my googling it looked like you needed to feed it a key in order to get information about it, thus made no sense to me.If you understand all this type of thing, what would be the minimum script I need just to get the current key press? That would be all I need to rewrite/modify my script to hopefully reduce my cpu usage. Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
kylomas Posted April 21, 2012 Share Posted April 21, 2012 _Guikeyproc looks like this Func _GUIKeyProc($hWnd, $Msg, $wParam, $lParam) EvaluateKey(Number($wParam)) EndFunc What DLL call? Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Morthawt Posted April 21, 2012 Author Share Posted April 21, 2012 This $aRet = DllCall('user32.dll', 'int', 'GetKeyNameText', 'int', $lParam, 'str', "", 'int', 256) I tried using that function you typed but it does not seem to work or do anything. When it comes to dealing with dll's or hooking I know absolutly nothing which is why I have had to make do with using _ispressed. Could you briefly explain how I can get the current key press into a variable? From there I can code everything I would need, I just need to some how get what ever the current key is. Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
kylomas Posted April 21, 2012 Share Posted April 21, 2012 (edited) Morthawt, My apologies, I am looking at source that pre-dates the source in the example scripts section. This must have been an earlier version <snip> I am sure that the version currently in examples scripts is better. Edited April 21, 2012 by Melba23 Code removed Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Morthawt Posted April 21, 2012 Author Share Posted April 21, 2012 Yeah all that source is way above my level of experience. I would literally need a cut down small piece of code that literally just gets the current key press, I could work with that then. I do not understand any of all this. Sorry for being a pain, but could you show me the absolute minimum code I would need to just get the key press information? If I can get that, thats all I need I should be able to use that and just buffer the last few presses and check for the existence of a prior arranged sequence of presses to perform an action myself. Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
kylomas Posted April 21, 2012 Share Posted April 21, 2012 (edited) No problem. This code was adapted from code originally published by Manadar and Gary Frost. <snip> Run it from SCite, type something into a comments section of the code and watch the console... Good Luck, kylomas Edited April 21, 2012 by Melba23 Code removed Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted April 21, 2012 Share Posted April 21, 2012 (edited) Incidentally, you will need to provide a way to exit... Edit: Comment - I would encourage you to spend some time with "hotstrings". It does EXACTLY what you are doing. Edited April 21, 2012 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Morthawt Posted April 21, 2012 Author Share Posted April 21, 2012 Yes I know it does "almost" what I want, I have security features and all sorts of things built into the one I am making. Plus I enjoy "making" rather than just using externally sourced UDF's. So the source you showed me last, I would need all of that entire thing to get the current keypress? I thought I found only what I needed so I took that into a new file and it did nothing until I had all of the source there. So there is no simple way to do a "hey windows, whats the current key press?" "Oh its err mmm 0x11" then? You have to use tons of code? Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
kylomas Posted April 21, 2012 Share Posted April 21, 2012 Your question is not that simple. You can call "getasynckeystate" at any time in a loop (similar to "ispressed"). You will then need to poll the keyboard iteratively. The technique used in "hotstrings" posts a message to your dummy gui which you then send to a function (no polling the keyboard). Timing issues are now reduced to "how quickly do you want to respond to a key/set of keys". In a sense you are saying "hey windows, whats the current key press?" "Oh its err mmm 0x11". But you need to code I posted to do that. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Morthawt Posted April 21, 2012 Author Share Posted April 21, 2012 Ok, if i wanted to call that in a loop, how would I do just that to get the current keypress? I am not in any dire need for a continuous detection like it detecting xxxxxxxxxxxxxxx in a couple miliseconds or anything. Currently my script waits until the current press has stopped and then will look for the next key. I just would like a better way to detect the key to begin with. So based on what you said, how would I call that in a loop to get the key press? I am thinking as simplistic as possible so I can make use of it. Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
kylomas Posted April 21, 2012 Share Posted April 21, 2012 That is the point, you do NOT call this in a loop to get a key press. When a key is pressed a message is posted to your dummy gui. In your case you might collect them in a string (like hotstrings does) and compare them to some array of values/actions (again, like hotstrings). All of the work is done withing the function "evaluatekey" (which, of course, can call other functions, your security for example). kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
spudw2k Posted April 21, 2012 Share Posted April 21, 2012 Here we go again... Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 21, 2012 Moderators Share Posted April 21, 2012 (edited) Morthawt, In both this thread and your previous one you have strayed too close to prohibited territory. As you quite clearly stated in that other thread: I know there are certain types of program banned from discussion/help in this forum and although my program is not bad, technically it could relatively easily be reconfigured for negative purposesYou should have taken your own advice. I don't want to get suspensions or bans due to just wanting feedback on my coding style on this oneIn that case I suggest you do not start any more threads about detecting the current keypress - the site owner does not want this sort of thing discussed here. I hope I made myself quite clear. M23 Edited April 21, 2012 by Melba23 Typo 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...
Recommended Posts