Sign in to follow this  
Followers 0
TheBytemaster

Keypress detection.

13 posts in this topic

Hello all!

I was looking for a solution to a question I had and wondered if any of you wonderful people could assist me.

I am wondering if it would be possible to simply determine when a user has pressed any key at all on a keyboard. I do not care about specific keys, but I want to know if such a thing would be possible to do without listening for every key on the keyboard, (which would be bad, because that would be like a keylogger, which is nothing at all like what I want, and is in fact against the rules of the forums as you probably already know), and how I might go about doing this. (I realize that there are some keys that are impossible to detect, such as the Fn key found on many laptops.)

So, to reiterate; I just want to know when any key at all is pressed. The key that is pressed isn't important at all. (In fact, a generic approach would be ideal to reduce complexity of the code.)

Thanks for your help!

Share this post


Link to post
Share on other sites



I am sure there was some "anykey" in the WinAPI function, but can't think of it now.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

hello TheBytemaster, and welcome to AutoIt and to the forum.

AutoIt has a function that will let you detect input for keyboard and mouse (and probably any other HID). look for:

_Timer_GetIdleTime()

but if it's only keyboard you are interested in, that a bit more complicated, i'll let the API/DLL gurus around take on it.

Share this post


Link to post
Share on other sites

Well if you suggest that then there is _WinAPI_GetIdleTime().


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Something like this?

#include <WindowsConstants.au3>
 
GUIRegisterMsg($WM_KEYDOWN, "IsPressed")
 
; do anything here
 
Func IsPressed()
    MsgBox(4096, "Test", "Key is pressed!", 2)
EndFunc

Share this post


Link to post
Share on other sites

 

Something like this?

#include <WindowsConstants.au3>
 
GUIRegisterMsg($WM_KEYDOWN, "IsPressed")
 
; do anything here
 
Func IsPressed()
    MsgBox(4096, "Test", "Key is pressed!", 2)
EndFunc

 

by MSDN: "Posted to the window with the keyboard focus". that's only for your GUI, so you can't detect keys sent to other windows with this method, right?

also, you'll have to register the WM_SYSKEYDOWN message, and still you'll probably miss some special keys.

1 person likes this

Share this post


Link to post
Share on other sites

by MSDN: "Posted to the window with the keyboard focus". that's only for your GUI, so you can't detect keys sent to other windows with this method, right?

also, you'll have to register the WM_SYSKEYDOWN message, and still you'll probably miss some special keys.

 

Aha, correct!

This will only detect keys for our own GUI and will not detect special keys.

Why OP want to detect any keys on ANY GUIs while he state it's nothing to do with keylogger?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

@michaelslamet, as far as i can read hes trying to detect idle keyboard with no mouse, what does that have to do with keylogger?

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

this seems a bit familiar to an issue i had in the past, only in reverse:

'?do=embed' frameborder='0' data-embedContent>>

so venturing into gedankenexperiment territory, i'd check the idle time. but if idle time reports activity, i'd check also for mouse moves, and assume a key press only if mouse did not move.

anyway i think it's time to let the OP get the reins now.

1 person likes this

Share this post


Link to post
Share on other sites

@michaelslamet, as far as i can read hes trying to detect idle keyboard with no mouse, what does that have to do with keylogger?

 

No? haha, my bad, Teacher :sweating:

Share this post


Link to post
Share on other sites

this seems a bit familiar to an issue i had in the past, only in reverse:

'?do=embed' frameborder='0' data-embedContent>>

so venturing into gedankenexperiment territory, i'd check the idle time. but if idle time reports activity, i'd check also for mouse moves, and assume a key press only if mouse did not move.

anyway i think it's time to let the OP get the reins now.

Ah, thank you. I believe that will do nicely. Thanks so much for your help!

 

Something like this?

#include <WindowsConstants.au3>
 
GUIRegisterMsg($WM_KEYDOWN, "IsPressed")
 
; do anything here
 
Func IsPressed()
    MsgBox(4096, "Test", "Key is pressed!", 2)
EndFunc

That's not what I was looking for as the others have stated, but $WM_KEYDOWN seems useful, and I might just use that in a later project I was brainstorming. I'll have to remember that one. Thanks!

(I didn't reply earlier because for some reason I wasn't getting any alerts for responses to my thread. I was actually kind of sad that I hadn't gotten any responses as far as I could tell, and I was about to try and figure out if bumping was acceptable here. I promise I'm not normally lazy with responses when people are kind enough to be helping me.) :P

Share this post


Link to post
Share on other sites

This post from Melba is a good start:

Ignore the mouse movement for the idle time, if you add also the mouse keypress ( _IsPressed ) then you have only the keyboard activity...

1 person likes this

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

This post from Melba is a good start:

Ignore the mouse movement for the idle time, if you add also the mouse keypress ( _IsPressed ) then you have only the keyboard activity...

So it is. I'm surprised I didn't see that earlier. Thanks.

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