Sign in to follow this  
Followers 0
jsteng

function to convert key to its _IsPressed equivalent.

10 posts in this topic

#1 ·  Posted (edited)

Is there a function that will convert a single key/char used with send to its equivalent keycode used by _IsPressed?

ie,

$key = "="

$keycode = FUNCTION($key) ;will convert "=" to "BB"

send("{"& $key & " down}")

_IsPressed($keycode) is true

 

it should work also for the other special characters like SHIFT, CTRL, ALT, SPACE, BACkSPACE... and so on.

$key = "SHIFT"

$keycode = FUNCTION($key) ;will convert "SHIFT" to "10"

send("{"& $key & " down}")

_IsPressed($keycode) is true

 

ASC?

 

Or perhaps something that is better/simpler than _IsPressed

ie

$key = "v"

send("{"& $key & " down}")

.

.

FunctionIsPressed($key) is true

 

bottom line, I dont like having to lookup the keycode that is used by IsPressed

Edited by jsteng

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

I'll not do this for you ( teach a man to fish bla bla ) but this is a good startup script, go, finish it and post the result:

P.S. There is CODE tag button, use it!

; Johnmcloud - 2014
#include <Misc.au3>

Local $hDLL = DllOpen("user32.dll")

ConsoleWrite("_IsPressed: BACKSPACE is equal to: " & _Hex_ToKey("BACKSPACE") & @CRLF)
ConsoleWrite("_IsPressed: TAB is equal to: " & _Hex_ToKey("TAB") & @CRLF)
ConsoleWrite("_IsPressed: JOHNCMLOUD is equal to: " & _Hex_ToKey("JOHNCMLOUD") & @CRLF)

$MyKey = _Hex_ToKey("TAB")
If $MyKey = "NOT_FOUND" Then Exit MsgBox(16, "Error", "Key wasn't found")

ConsoleWrite("Press TAB to exit from the script" & @CRLF)

While Not _IsPressed($MyKey, $hDLL)
    ConsoleWrite("Waiting for TAB..." & @CRLF)
    Sleep(100)
WEnd

Func _Hex_ToKey($sHexKey)
    Local $aArray[2][2] = [["BACKSPACE", "TAB"],["08", "09"]]
    For $i = 0 To UBound($aArray) - 1
        If $aArray[0][$i] = $sHexKey Then Return $aArray[1][$i]
    Next
    Return "NOT_FOUND" ; whatever error if the key wasn't find by For...Next
EndFunc   ;==>_Hex_ToKey

http://www.autoitscript.com/wiki/Arrays

Edited by johnmcloud

Share this post


Link to post
Share on other sites

Hi,

Before this thread goes any further, can I just remind everyone about the prohibition on keyloggers. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

rest assured this is NOT a keylogger app nor other prohibited apps

besides, there are other programming languages that can do that purpose better and easier

Edited by jsteng

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

jsteng,

Can you explain more about what you are trying to do?  Particularly what you are trying to do with IsPressed() and Send(). 

There may be alternatives once we understand your task.

kylomas

edit: spelling

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Hi,

 

Can you explain more about what you are trying to do?

 

a$ = inkey$      REM if i remember correctly from GW-Basic 1983 or 84, returns the pressed key....

 

I don´t know why this BASIC (hehe, isn´t that funny^^) function to get a keyboard-code is not implemented in AutoIt. "Prohibition on keyloggers" is a weak excuse. 

Share this post


Link to post
Share on other sites

Don't understand the fuss and confusion.

All the codes are in the respective documentation.

Func _IsPressedCode($char)
    Switch $char
        Case "A"
            Return "42"
        Case "B"
            Return "43"
            ;etc...
    EndSwitch
EndFunc

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

AndyG,

 

"Prohibition on keyloggers" is a weak excuse

But that is one of the rules here as set out by the AutoIt site owner and author. If you want to post here, then you need to respect them. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

jsteng,

I am sure you are not writing a keylogger - but you still need to respect the guidance in the thread to which I linked. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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