Sign in to follow this  
Followers 0
-TS-

alittle help plz

7 posts in this topic

dont think this is possable, but is there a way to know if a key on the keyboard is pressed?

Share this post


Link to post
Share on other sites



I dont' think there is any function currently in AutoIt, However you can set up hotkeys in AutoHotkey v0.213 BETA.

This would allow you to set up tests and things for keys pressed.

If you are trying to make a key logger of sorts, it would be hard (cheer) but if you want to have something happen when a certain key gets pressed, AutoHotkey may be the right tool.

Not knowing your actual application limits my answer.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

im anti-keylogger (got burned way to many times)

i was thnking of

if -s pressed- then
  send("sleep()")
 endif
if -w pressed- then
  send("send(up)")
 endif
...
...

for fast coding :whistle:

Share this post


Link to post
Share on other sites

Ah, I use shortcuts all the time in coding, I use UltraEdit 32 to do it mostly, and it has very easy macros, and I can load up custom sets depending on what I am doing.

I think AutoHotkey would be the way for some of that if you have no macros set in what ever program you are useing.

I would use some type of control character or such, as hitting only S for sleep() would find you in all sorts of trouble.

AutoHotkey has all sorts of hotkey possibilities, and is in the easy to use AutoIt 2 format for most commands. Send works really great. :whistle:

Still available at http://home.tampabay.rr.com/kodi/ahk/README.htm if I am not mistaken, cmallett??

Well it works very nice, and doens't take too long to figure out.

I am still a fan of UltraEdit32 for fast editting.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Yeah that's the link.

In addition to defining hotkeys, you can use its GetKeyState command. Here are some excerpts from the docs:

GetKeyState, OutputVar, LButton

It sets OutputVar to be U (for up), D (for down), or blank if the state couldn't be determined for any reason. The key name can be virtually any of the keys listed in the documentation, including mouse buttons (at least under WinXP, and they will probably work on other OSes as well).

GetKeyState now supports an optional 3rd arg that can be the letter T (state of toggleable key such as CapsLock) or P (physical state of key). If the arg is omitted or blank, the logical state of the key will be returned. The logical state should be one that the OS and the foreground app believe the key to be in, whereas the physical state is whether the key or mouse button is physically down or up. Example:

GetKeyState, state, CapsLock, T ; Will set "state" to be D if CapsLock is ON or U otherwise.

Also, you can easily define context sensitive hotkeys, even using ordinary letters. Example:

w::
IfWinNotActive, SomeApp
     Send, w  ; Send the key through (use its native function)
else
{
     Send, {UP}
    ; and do whatever else you want to do
}
return

And by popular demand, you can even log keys and mouse buttons with the Keylog command (see docs for details).

Edited by cmallett

Share this post


Link to post
Share on other sites

w::

IfWinNotActive, SomeApp

    Send, w  ; Send the key through (use its native function)

else

{

    Send, {UP}

; and do whatever else you want to do

}

return

I forgot, but I think replacing w with w is removed from your program by default in the new version to stop endless loops?


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Good catch! It would cause an infinite loop, which the program would catch and warn you about.

To avoid that, simply add a dollar sign ($) before the W so that the hook will be used to implement the key. The hook is smart enough to not consider the Send command's keystrokes as hotkeys:

$w::
IfWinNotActive, - metapad
    Send, w ; Send the key through (use its native function)
else
{
    Send, {UP}
 ; and do whatever else you want to do
}
return

Note: The $ method only works on WinNT/2k/XP/2003 at the moment, since the hook is of a type that can't work on Win9x.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0