misrepresentative Posted December 7, 2016 Share Posted December 7, 2016 (edited) ; .... While 1 Switch TrayGetMsg() Case $id_Exit Exit Case $id_Test _test() EndSwitch If _IsPressed("23", $USER32_DLL) Then _example() EndIf WEnd For example, it may not work as expected under abnormal conditions such as high CPU utilization. If you press End key ("23"), it's not guaranteed that key press is detected. Could you kindly recommend me a way to improve it? (note: without using Hotkeyset, if possible.) Many thanks in advance for you time. Edited December 9, 2016 by misrepresentative added another case (for better ilustration) Link to comment Share on other sites More sharing options...
water Posted December 7, 2016 Share Posted December 7, 2016 Welcome to AutoIt and the forum! user32.dll is the default. To which value do you set variable $USER32_DLL? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
misrepresentative Posted December 7, 2016 Author Share Posted December 7, 2016 Thank you, water. Sorry if I'm misunderstanding but does it really matter? Local $USER32_DLL = DllOpen("user32.dll") If $USER32_DLL = -1 Then MsgBox($MB_ICONERROR + $MB_OK, "Error- DllOpen", "Unable to open user32.dll for use." & @CRLF & "Application will now exit.") Exit EndIf OnAutoItExitRegister("On_Exit") Func On_Exit() DllClose($USER32_DLL) EndFunc ;==>On_Exit ; ... Link to comment Share on other sites More sharing options...
misrepresentative Posted December 9, 2016 Author Share Posted December 9, 2016 Sorry for kind of bumping it. Maybe the issue is triggered by TrayGetMsg() as it does not poll tray timely enough? Link to comment Share on other sites More sharing options...
spudw2k Posted December 9, 2016 Share Posted December 9, 2016 That's a pretty vague issue to solve. Since _IsPressed is evaluating the state of the keyboard, it is necessarily going to execute at the whim of CPU scheduling. A hotkey might be better as it should trigger an, "as on demand as possible" event...depending on what you are really looking to do. Why isn't hotkey an option for you? 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 Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool 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...
misrepresentative Posted December 9, 2016 Author Share Posted December 9, 2016 I am launching applications in protected environment(s) for various testing purposes. Hotkeys are dangerous from a security point of view & not allowed to be set. Link to comment Share on other sites More sharing options...
SadBunny Posted December 9, 2016 Share Posted December 9, 2016 You're not allowed to write code that is executed on keypress, so to work around that you are writing code that is executed on keypress? Roses are FF0000, violets are 0000FF... All my base are belong to you. Link to comment Share on other sites More sharing options...
Bert Posted December 9, 2016 Share Posted December 9, 2016 Hotkeyset is dangerous if and ONLY if you have a blanket hotkeyset that is active as long as the script is running. The trick is have in your loop on the top level this: sleep (100 if winactive then call a function that turns on the hotkeyset a sub loop after that in the function that will look for what you want AND if the window is still active or not. If the window you have the hotkeyset is no longer active - turn off the hotkeyset This type of setup is very common in many applications that has keys set to do specific functions. For example pressing the F3 key in Firefox opens the text search function. misrepresentative 1 The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
misrepresentative Posted December 9, 2016 Author Share Posted December 9, 2016 23 minutes ago, SadBunny said: You're not allowed to write code that is executed on keypress, so to work around that you are writing code that is executed on keypress? Disclaimer: I'm not a programmer. I'm breaking stuff as a hobby. Volunteering if you want. Do note that I did not create the environment. (It's like a Sandbox if you're familiar with the concept.) Hope it doesn't go really that off-topic. Sorry about it. I might be wrong but here's an example : it's possible to block input by setting hotkeys. Now, is it possible to use _IsPressed to block input? Probably not. Another reason is that in such protected environments, you need compatibility as well. It affects compatibility of applications. (If you find a way to block it then another method should be found.) To me it seems more risky to set hotkeys at first-sight. Please correct me if I'm wrong. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 9, 2016 Developers Share Posted December 9, 2016 1 minute ago, misrepresentative said: To me it seems more risky to set hotkeys at first-sight. Don't know what that means. You can set/disable the HotKeySet() at any time in the script so you are always in control. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
misrepresentative Posted December 9, 2016 Author Share Posted December 9, 2016 (edited) Yes, Jos. You are right but unknown application run as well. There is a higher risk with unknown applications. Thanks. Edited December 9, 2016 by misrepresentative Link to comment Share on other sites More sharing options...
Developers Jos Posted December 9, 2016 Developers Share Posted December 9, 2016 Why? what is the difference? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
misrepresentative Posted December 9, 2016 Author Share Posted December 9, 2016 Unknown and possibly malicious applications run in the environment. Trusted applications do not. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 9, 2016 Developers Share Posted December 9, 2016 I mean between the use of _IsPressed() and HotKeySet()? Well aware of security risks and keylogging, but then is this discussion in the amateur league, but are not going down that road here. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
misrepresentative Posted December 9, 2016 Author Share Posted December 9, 2016 I think there is a misunderstanding. Sorry. English is not my native language. It's simply not possible to use HotKeySet in my case. It is considered more risky with mentioned environment. I just can't use it-- it's blocked. Link to comment Share on other sites More sharing options...
misrepresentative Posted December 9, 2016 Author Share Posted December 9, 2016 47 minutes ago, Bert said: Hotkeyset is dangerous if and ONLY if you have a blanket hotkeyset that is active as long as the script is running. The trick is have in your loop on the top level this: sleep (100 if winactive then call a function that turns on the hotkeyset a sub loop after that in the function that will look for what you want AND if the window is still active or not. If the window you have the hotkeyset is no longer active - turn off the hotkeyset This type of setup is very common in many applications that has keys set to do specific functions. For example pressing the F3 key in Firefox opens the text search function. What if the user intends to use the key at the same time? eg not working with active window Thanks. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 9, 2016 Developers Share Posted December 9, 2016 23 minutes ago, misrepresentative said: It is considered more risky with mentioned environment. So back to my original question: Why? What is the difference? Jos misrepresentative 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
misrepresentative Posted December 9, 2016 Author Share Posted December 9, 2016 Because you can block keyboard input with it. That's one example. eg make it do nothing on all keyboard keys Link to comment Share on other sites More sharing options...
Developers Jos Posted December 9, 2016 Developers Share Posted December 9, 2016 Ok, I am going to exit this conversation as it's not making much sense to me and there are way better ways to accomplish that but that isn't going to be discussed here as that can be used for malicious purposes. Good luck with your scripting! Jos misrepresentative 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
BrewManNH Posted December 9, 2016 Share Posted December 9, 2016 @misrepresentative If you're script has a GUI, then you can use accelerator keys, they are only active when the GUI is active. If you're just monitoring for key presses using _IsPressed or _WinAPI_GetAsyncKetState then you're at the whim of the timing available to the script to read from the keyboard, this will be CPU dependent and also depends on whatever else might be running at the time. BTW, you can block any/all keyboard input very easily without ever using HotKeys, so the prohibition you have against them is ludicrous. misrepresentative 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator 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