Jump to content

Recommended Posts

Posted (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 by mahaju
Posted

Interesting idea. What's it going to be used for?

  Reveal hidden contents

 

Posted

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

Posted (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 inactive

But 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 by mahaju
Posted (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-hooks

By the way your post reminded me of something

I once had seen a screensaver that could take input from the mouse, without exiting

Perhaps it's logic is similar to what I need to do

However that screensaver started if both keyboard and Mouse were idle

In my case I just want to keep track of keyboard idle time and ignore the mouse movements to determine if the timer should be reset

I 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 by mahaju
Posted (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

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 by mahaju
Posted (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 by mahaju
  • Moderators
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...