Jump to content

Check which key is pressed


Timppa
 Share

Recommended Posts

Hello!

For my program, there is default "F1" for pausing the program, but as my Mac user friend somehow cannot use F1 because it does something else, I want to make a Function that sets the pause key to next pressed letter. I know it will use _IsPressed() method and so on, I can do all this by myself but I am not sure how to detect which button was sent?

And no, I am not making a keylogger as many of you might think. It is alot of easier to make with another language :)

And by the way, I have a label that says "Pause: " and then there is a input kind of box and when you press G for example, the input box has G in it, but the input box would not be editable, only changing if pressed a button and then pressing any keyboard key. However, if I do not find a solution, I could use that input box and make another button that has "Set" in it, just wondering if this is possible to "track" which keyboard is pressed.

And I know the rest of the script, it would be this:

Global $DefinePause

HotKeySet($DefinePause, "Pause")

Func Pause()
    ;The advanced pause code I got from this forum
EndFunc

Thanks in advance! If it feels like I am breaking the forum rules (as this could be used as keylogger as well), then tell me and I just use the novice input box style :>

 

EDIT: However, if the user sets F2 as pause button, it will not type it into the input box if I use it that way :(

Edited by Timppa
Link to comment
Share on other sites

I checked from google before I posted and saw no real solution for this; only what I found out was _Timer_GetIdleTime but I guess it interacts if your mouse has moved. I don't want to see any mouse movement since you cannot set mouse for pause.

And yeah, that is why I want to make it customable pause. And I totally forgot, he has Windows on his Mac. This is also good if I want to change the button without opening the script folder and edit the script.

Link to comment
Share on other sites

Gives an example of when the hex key 23 is pressed. From the _IsPressed help file

https://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm

Hex 23 is "End"

You would need call a function with a while loop that will wait until a key is pressed then assign it to your value. You don't have to record which key is pressed, just convert it to a char and assign it in Hotkeyset

This example would work very well for any of the regular characters of the keyboard but you'll have to figure out how to get the Special characters (Esc, F1-F12, End, Insert, etc)

<snip>

 

Edited by Melba23
Removed code
Link to comment
Share on other sites

  • Moderators

InunoTaishou,

Once again you have posted code which scans the entire keyboard. For the last time I am limiting my involvement to pointing you to this announcement - any future posts contrary to the very clear guidance given in that thread will see you sanctioned.

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:

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

InunoTaishou,

Once again you have posted code which scans the entire keyboard. For the last time I am limiting my involvement to pointing you to this announcement - any future posts contrary to the very clear guidance given in that thread will see you sanctioned.

M23

So is the thing I asked for not allowed in this forum? If so, then I am sorry. Only wanted a function to set custom key.

Link to comment
Share on other sites

  • Moderators

Timppa,

As you can see from the announcement to which I linked, we have very strict limits on key "tracking". I fully realise that making a keylogger is not the intent (as you yourself highlighted in the OP) but if the resulting code performs essentially the same actions, then it falls under the same rules.

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:

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

I dont understand. I have a little script that is linked to keyboard buttons. Like F1 to open Help - am I missing something?  This should really not be difficult to do?

Have you looked at this?  Maybe I do not understand the problem.

Wiki FAQ Why does the Ctrl key get stuck down after I run my script?

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

I dont understand. I have a little script that is linked to keyboard buttons. Like F1 to open Help - am I missing something?  This should really not be difficult to do?

Have you looked at this?  Maybe I do not understand the problem.

Wiki FAQ Why does the Ctrl key get stuck down after I run my script?

im aa liltle durnk so i dont know if im stupd but how oes that has naything to do whit my scrpt?

EDIT i mean with ths topic and happy new year t every1!

Edited by Timppa
Link to comment
Share on other sites

#include <misc.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIvkeysConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Input;Variable to set the pause function to

HotKeySet("{PAUSE}","SetPause")

While 1
    Sleep(100)
WEnd

Func SetPause()
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 253, 95, 292, 146)
$Label1 = GUICtrlCreateLabel("Enter the key to be set to pause and click OK", 24, 16, 219, 17)
$Input1 = GUICtrlCreateInput("", 40, 48, 49, 21)
$OKButton = GUICtrlCreateButton("OKButton", 144, 48, 73, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OKButton
            $Input = GUICtrlRead($Input1)
            HotKeySet($Input,"Success")
            GUISetState(@SW_HIDE)
    EndSwitch
WEnd

EndFunc

Func Success()
    MsgBox(0,"","Success")
EndFunc

Here's my attempt. It works. Press the pause key then set the hotkey to another variable. It's long winded but it works.

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

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...