mahaju Posted April 24, 2013 Posted April 24, 2013 (edited) HI I am new to autoit and this is my first script Is there any finction that detects when a key has been pressed on the keyboard? _KeyPressed() seems to check if some particular key was pressed, but I want something that gives a signal is any ley is pressed on the keyboard I also need to make a timer, which counts the number of seconds elapsed I want to be able to display the number of seconds elapsed in a window and reset the timer to 0 is any key is pressed on the keyboard (but should ignore mouse buttons or movement) So far I have found the _KeyPressed() finction and the _timer functions, but they don't quite do exactly what I need Please give me some ideas on how I should go about this Thank you Edited April 24, 2013 by mahaju
Mechaflash Posted April 24, 2013 Posted April 24, 2013 Interesting idea. What's it going to be used for? Reveal hidden contents “Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”
Bert Posted April 24, 2013 Posted April 24, 2013 What you are asking for is basically a keystroke logger. Please understand the topic of keyloggers is banned in the forum. Now, I take it you want to do something that works on the principle of a screensaver but in your case it just resets the timer. I found a link to some code (Not AutoIt) but it should be able to give you some direction. http://www.codeproject.com/Articles/37666/Calculate-system-idle-time-without-hooks The Vollatran project My blog: http://www.vollysinterestingshit.com/
Bert Posted April 24, 2013 Posted April 24, 2013 (edited) Also look at this google search resulthttps://www.google.com/search?q=api+calculate+windows+idle+time Edited April 24, 2013 by YogiBear The Vollatran project My blog: http://www.vollysinterestingshit.com/
MouseSpotter Posted April 24, 2013 Posted April 24, 2013 (edited) Use #include _InputEvent_StartUp() GUICreate("Key input captured here") GUISetState(@SW_SHOW) While True Wend Func _InputEvent_KeyUp($handle,$keyname,$keyvalue,$shift,$ctrl,$alt,$ticks) if $keyname = "ESC" Then Exit endif ToolTip(StringFormat("You pressed the %s [%s] key",$keyname,$keyvalue)) EndFunc Edited April 24, 2013 by MouseSpotter
mahaju Posted April 25, 2013 Author Posted April 25, 2013 (edited) Thanks for the replies On 4/24/2013 at 4:51 PM, 'Mechaflash said: Interesting idea. What's it going to be used for?I want the computer to go to sleep if the keyboard is inactiveBut I want to be able to use the mouse during this time though, which does not seem to be possible through Windows, as it keeps track of keyboard as well as mouse before making the computer go into sleep or hibernation mode or running any other program for that matter Edited April 25, 2013 by mahaju
mahaju Posted April 25, 2013 Author Posted April 25, 2013 (edited) On 4/24/2013 at 4:55 PM, 'YogiBear said: What you are asking for is basically a keystroke logger. Please understand the topic of keyloggers is banned in the forum.Now, I take it you want to do something that works on the principle of a screensaver but in your case it just resets the timer. I found a link to some code (Not AutoIt) but it should be able to give you some direction.http://www.codeproject.com/Articles/37666/Calculate-system-idle-time-without-hooksBy the way your post reminded me of somethingI once had seen a screensaver that could take input from the mouse, without exitingPerhaps it's logic is similar to what I need to doHowever that screensaver started if both keyboard and Mouse were idleIn my case I just want to keep track of keyboard idle time and ignore the mouse movements to determine if the timer should be resetI don't need it to work in any kind of stealth mode, and in fact, I need a window to be visible so that I can keep track of the current timer value Edited April 25, 2013 by mahaju
mahaju Posted April 25, 2013 Author Posted April 25, 2013 (edited) Ok I have achieved, somewhat, what I wanted to do the code is very crude but I want to post it here so that some experienced users may provide some other ideas or suggestions for code improvement Reveal hidden contents #include #include #include local $upper_limit, $counter, $hWnd, $i, $hDLL, $labelwidth, $labelheight, $label1_id, $label2_id $hDLL = DllOpen("user32.dll"); $upper_limit = 5400 $counter = 0 $iElapse = 1000 $labelwidth = 100 $labelheight = 25 $hWnd = GUICreate("Show Counter") GUISetState(@SW_SHOW) $label1_id = GUICtrlCreateLabel($counter, -1, -1, $labelwidth, $labelheight) $label2_id = GUICtrlCreateLabel($upper_limit, 50, 50, 100, $labelheight) GUICtrlSetFont ($label1_id, 20, 600) GUICtrlSetFont ($label2_id, 20, 600) do $i = 1 while $i <= 40 sleep(25); if _IsPressed("20", $hDLL) OR _IsPressed("41", $hDLL) OR _IsPressed("45", $hDLL) OR _IsPressed("49", $hDLL) OR _IsPressed("4F", $hDLL) OR _IsPressed("55", $hDLL) OR _IsPressed("20", $hDLL) OR _IsPressed("53", $hDLL) then $counter = 0; exitloop endif $i = $i + 1 if GUIGetMsg() = $GUI_EVENT_CLOSE then exit endif wend GUICtrlSetData($label1_id, $counter) $counter = $counter + 1 until $counter > $upper_limit DllClose ( $hDLL ) Run(@SystemDir & "\shutdown.exe /f /s /t 10", "", @SW_MAXIMIZE) exit It shuts down the computer after 1.5 hours of keyboard inactivity, and any user input from the mouse during this time will not affect it The thing I like most about this is that it detects input even when the script's window is not in focus How does AutoIt do that anyway? What would be an easier way to determine if any key on the keyboard had been used at all, without having to download anything else? Anyway this solves what I need for now PS: and how do I make the #include's show up between the tags here? Edited April 25, 2013 by mahaju
mahaju Posted April 25, 2013 Author Posted April 25, 2013 (edited) how about not logging whatever it was that we detected? that wouldn't technically be a keylogger would it? Anyway, isn't there any function at all that let's you find out just if the keyboard has been used, instead of only those checking if some particular keys have been pressed? Edited April 26, 2013 by mahaju
Moderators Melba23 Posted April 25, 2013 Moderators Posted April 25, 2013 mahaju, Quote how about not logging whatever it was that we detected? that wouldn't technically be a keylogger would it?Please read the announcement I posted about keyboard watching scripts. It does not matter if you do not log the return - merely checking for the keys is not allowed as it is trivial to log if the code to detect is provided. It is actually pretty trivial to detect keypresses as well - but as the site owner does not want such matters discussed on the forum that is an end to 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: Reveal hidden contents 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
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