Jump to content

What is the best way to look for a keystroke?


lugosi
 Share

Go to solution Solved by MikahS,

Recommended Posts

Within the program that I am writing, I want to check to see if certain keys are pressed, very much like a hotkey. Is it best to use the HotKeySet command, or should I use some different method for waiting for the keypress? The thing that I dont like about HotKeySet (it isn't an intense dislike, just a nagging niggle) is that it 'hijacks' that key for the entire run of the program (just like a good hotkey should!) even if my program is not the program in focus at the time.

Thanks in advance for any help you can give.

Link to comment
Share on other sites

  • Solution

I don't like _IsPressed. I just used this in my app, and I did not like it as it will not work once a key has already been pressed. Very crude, but using Accelerators is they way to go:

Local $aAccelKeys[1][1] = [["{TAB}", $exTab]]
GUISetAccelerators($aAccelKeys, $hwnd)
; example
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $exTab
            ; run whatever you want here
    EndSwitch
WEnd
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

  • Moderators

Lugosi,

Or GUISetAccelerators - they are like HotKeys but are only active when you GUI has focus so they should not "niggle". :D

Could I also point you at this announcement - not suggesting your intent is to create a keylogger, but just to make our stance on such matters quite clear. ;)

M23

Edit: I see I am getting slower as I age. :(

Edited by Melba23

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:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba, your knowledge is much greater though ;)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

I can assure you that this is not for a keylogger of any kind. I am creating a program to update/change the OEM configuration information on a PC for my company. We want to be able to brand our computers with our logo and information. I have created quite a nice program if I might say so :) This is my first real foray  into AutoIT programming (and the first programming that I have done in MANY years, not that I was ever a great programmer to begin with.....it is a hobby to me).

Thank you for all of the advice.....esp. that about the keylogger stuff! I gotta be careful how I phrase things so as not to be banished :o

Link to comment
Share on other sites

I just replaced hotkeys with accelerators, and it worked like a charm :)

 

Glad to help ;)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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