Jump to content

I'm Looking for a what key pressed udf or method..


smashly
 Share

Recommended Posts

Hi,

I'm about to incorperate user customiseable hotkeys into my utilitray script and was wondering if there is a udf that can tell me which key is pressed on the keyboard?

I've been working with _IsPressed udf to do what I'm after, but I find it's like I have to write a whole table of hex values for all keys to an array just so I can identify the key that is pressed then translate the pressed key to a hotkey (as well as a display version for user). Surely there is a udf or dll call that I can use that can identify the key pressed for a quick translation into a hotkey format. I feel my searches just seem to lead me further from what I'm looking for (but I learn all types of other stuff allong the way).

I'm not looking for anyone to write a script for me (as it would take the fun out of it), but some pointers in the right direction would be appreciated. Surely there is a more efficient way to do it?

Ruff example of what I mean how to identify the key pressed using _IsPressed udf:

#include <GUIConstants.au3>
#include <Misc.au3>

$main = GUICreate(" My GUI", 320,120, @DesktopWidth/2-160, @DesktopHeight/2-45, -1)
$file = GUICtrlCreateInput ( "", 10,  5, 300, 20)
$btn = GUICtrlCreateButton ("Capture", 40,  75, 60, 20)

GUISetState ()

$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
        GUICtrlSetState($btn, $GUI_DISABLE)
        GUICtrlSetState($file, $GUI_FOCUS)
        _KeyConvert()
        GUICtrlSetState($btn, $GUI_ENABLE)
    EndSelect
Wend

Func _KeyConvert()
    Dim $ok[1]
    Dim $key[3][64]
    $key[0][0] = "0D";ENTER key
    $key[1][0] = "{" & "ENTER" & "}";ENTER send
    $key[2][0] = "ENTER";ENTER display
    $key[0][1] = "10";SHIFT key
    $key[1][1] = "+";SHIFT send
    $key[2][1] = "SHIFT";SHIFT display
    $key[0][2] = "11";CTRL key
    $key[1][2] = "^";CTRL send
    $key[2][2] = "CONTROL";CTRL display
    $key[0][3] = "12";ALT key
    $key[1][3] = "!";ALT send
    $key[2][3] = "ALT";ALT display
    $key[0][4] = "1B";ESC key
    $key[1][4] = "{" & "ESC" & "}";ESC send
    $key[2][4] = "ESCAPE";ESC display
    $key[0][5] = "20";SPACEBAR key
    $key[1][5] = "{" & "SPACE" & "}";SPACEBAR send
    $key[2][5] = "SPACE";SPACEBAR display
    $key[0][6] = "21";PAGE UP key
    $key[1][6] = "{" & "PGUP" & "}";PAGE UP send
    $key[2][6] = "PAGE UP";PAGE UP display
    $key[0][7] = "22";PAGE DOWN key
    $key[1][7] = "{" & "PGDN" & "}";PAGE DOWN send
    $key[2][7] = "PAGE DOWN";PAGE DOWN display
    $key[0][8] = "23";END key
    $key[1][8] = "{" & "END" & "}";END send
    $key[2][8] = "END";END display
    $key[0][9] = "24";HOME key
    $key[1][9] = "{" & "HOME" & "}";HOME send
    $key[2][9] = "HOME";HOME display
    $key[0][10] = "25";LEFT ARROW key
    $key[1][10] = "{" & "LEFT" & "}";LEFT ARROW send
    $key[2][10] = "LEFT ARROW";LEFT ARROW display
    $key[0][11] = "26";UP ARROW key
    $key[1][11] = "{" & "UP" & "}";UP ARROW send
    $key[2][11] = "UP ARROW";UP ARROW display
    $key[0][12] = "27";RIGHT ARROW key
    $key[1][12] = "{" & "RIGHT" & "}";RIGHT ARROW send
    $key[2][12] = "RIGHT ARROW";RIGHT ARROW display
    $key[0][13] = "28";DOWN ARROW key
    $key[1][13] = "{" & "DOWN" & "}";DOWN ARROW send
    $key[2][13] = "DOWN ARROW";DOWN ARROW display
    $key[0][14] = "2D";INS key
    $key[1][14] = "{" & "INS" & "}";INS send
    $key[2][14] = "INSERT";INS display
    $key[0][15] = "2E";DEL key
    $key[1][15] = "{" & "DEL" & "}";DEL send
    $key[2][15] = "DELETE";DEL display
    $key[0][16] = "30";0 key
    $key[1][16] = "0";0 send
    $key[2][16] = "0";0 display
    $key[0][17] = "31";1 key
    $key[1][17] = "1";1 send
    $key[2][17] = "1";1 display
    $key[0][18] = "32";2 key
    $key[1][18] = "2";2 send
    $key[2][18] = "2";2 display
    $key[0][19] = "33";3 key
    $key[1][19] = "3";3 send
    $key[2][19] = "3";3 display
    $key[0][20] = "34";4 key
    $key[1][20] = "4";4 send
    $key[2][20] = "4";4 display
    $key[0][21] = "35";5 key
    $key[1][21] = "5";5 send
    $key[2][21] = "5";5 display
    $key[0][22] = "36";6 key
    $key[1][22] = "6";6 send
    $key[2][22] = "6";6 display
    $key[0][23] = "37";7 key
    $key[1][23] = "7";7 send
    $key[2][23] = "7";7 display
    $key[0][24] = "38";8 key
    $key[1][24] = "8";8 send
    $key[2][24] = "8";8 display
    $key[0][25] = "39";9 key
    $key[1][25] = "9";9 send
    $key[2][25] = "9";9 display
    $key[0][26] = "41";A key
    $key[1][26] = "a";a send
    $key[2][26] = "A";A display
    $key[0][27] = "42";B key
    $key[1][27] = "b";b send
    $key[2][27] = "B";B display
    $key[0][28] = "43";C key
    $key[1][28] = "c";c send
    $key[2][28] = "C";C display
    $key[0][29] = "44";D key
    $key[1][29] = "d";d send
    $key[2][29] = "D";D display
    $key[0][30] = "45";E key
    $key[1][30] = "e";e send
    $key[2][30] = "E";E display
    $key[0][31] = "46";F key
    $key[1][31] = "f";f send
    $key[2][31] = "F";F display
    $key[0][32] = "47";G key
    $key[1][32] = "g";g send
    $key[2][33] = "G";G display
    $key[0][33] = "48";H key
    $key[1][33] = "h";h send
    $key[2][33] = "H";H display
    $key[0][34] = "49";I key
    $key[1][34] = "i";i send
    $key[2][34] = "I";I display
    $key[0][35] = "4A";J key
    $key[1][35] = "j";j send
    $key[2][35] = "J";J display
    $key[0][36] = "4B";K key
    $key[1][36] = "k";k send
    $key[2][36] = "K";K display
    $key[0][37] = "4C";L key
    $key[1][37] = "l";l send
    $key[2][37] = "L";L display
    $key[0][38] = "4D";M key
    $key[1][38] = "m";m send
    $key[2][38] = "M";M display
    $key[0][39] = "4E";N key
    $key[1][39] = "n";n send
    $key[2][39] = "N";N display
    $key[0][40] = "4F";O key
    $key[1][40] = "o";o send
    $key[2][40] = "O";O display
    $key[0][41] = "50";P key
    $key[1][41] = "p";p send
    $key[2][41] = "P";P display
    $key[0][42] = "51";Q key
    $key[1][42] = "q";q send
    $key[2][42] = "Q";Q display
    $key[0][43] = "52";R key
    $key[1][43] = "r";r send
    $key[2][43] = "R";R display
    $key[0][44] = "53";S key
    $key[1][44] = "s";s send
    $key[2][44] = "S";S display
    $key[0][45] = "54";T key
    $key[1][45] = "t";t send
    $key[2][45] = "T";T display
    $key[0][46] = "55";U key
    $key[1][46] = "u";u send
    $key[2][46] = "U";U display
    $key[0][47] = "56";V key
    $key[1][47] = "v";v send
    $key[2][47] = "V";V display
    $key[0][48] = "57";W key
    $key[1][48] = "w";w send
    $key[2][48] = "W";W display
    $key[0][49] = "58";X key
    $key[1][49] = "x";x send
    $key[2][49] = "X";X display
    $key[0][50] = "59";Y key
    $key[1][50] = "y";y send
    $key[2][50] = "Y";Y display
    $key[0][51] = "5A";Z key
    $key[1][51] = "z";z send
    $key[2][51] = "Z";Z display
    $key[0][52] = "60";NUMBERPAD 0 key
    $key[1][52] = "{" & "NUMPAD0" & "}";NUMBERPAD 0 send
    $key[2][52] = "NUMBERPAD 0";NUMBERPAD 0 display
    $key[0][53] = "61";NUMBERPAD 1 key
    $key[1][53] = "{" & "NUMPAD1" & "}";NUMBERPAD 1 send
    $key[2][53] = "NUMBERPAD 1";NUMBERPAD 1 display
    $key[0][54] = "62";NUMBERPAD 2 key
    $key[1][54] = "{" & "NUMPAD2" & "}";NUMBERPAD 2 send
    $key[2][54] = "NUMBERPAD 2";NUMBERPAD 2 display
    $key[0][55] = "63";NUMBERPAD 3 key
    $key[1][55] = "{" & "NUMPAD3" & "}";NUMBERPAD 3 send
    $key[2][55] = "NUMBERPAD 3";NUMBERPAD 3 display
    $key[0][56] = "64";NUMBERPAD 4 key
    $key[1][56] = "{" & "NUMPAD4" & "}";NUMBERPAD 4 send
    $key[2][56] = "NUMBERPAD 4";NUMBERPAD 4 display
    $key[0][57] = "65";NUMBERPAD 5 key
    $key[1][57] = "{" & "NUMPAD5" & "}";NUMBERPAD 5 send
    $key[2][57] = "NUMBERPAD 5";NUMBERPAD 5 display
    $key[0][58] = "66";NUMBERPAD 6 key
    $key[1][58] = "{" & "NUMPAD6" & "}";NUMBERPAD 6 send
    $key[2][58] = "NUMBERPAD 6";NUMBERPAD 6 display
    $key[0][59] = "67";NUMBERPAD 7 key
    $key[1][59] = "{" & "NUMPAD7" & "}";NUMBERPAD 7 send
    $key[2][59] = "NUMBERPAD 7";NUMBERPAD 7 display
    $key[0][60] = "68";NUMBERPAD 8 key
    $key[1][60] = "{" & "NUMPAD8" & "}";NUMBERPAD 8 send
    $key[2][60] = "NUMBERPAD 8";NUMBERPAD 8 display
    $key[0][61] = "69";NUMBERPAD 9 key
    $key[1][61] = "{" & "NUMPAD9" & "}";NUMBERPAD 9 send
    $key[2][61] = "NUMBERPAD 9";NUMBERPAD 9 display
    $key[0][62] = "6A";NUMBERPAD MULTIPLY key
    $key[1][62] = "{" & "NUMPADMULT" & "}";NUMBERPAD MULTIPLY send
    $key[2][62] = "NUMBERPAD MULTIPLY";NUMBERPAD MULTIPLY display
    $key[0][63] = "6B";NUMBERPAD ADD key
    $key[1][63] = "{" & "NUMPADADD" & "}";NUMBERPAD ADD send
    $key[2][63] = "NUMBERPAD ADD";NUMBERPAD ADD display

    $dll = DllOpen("user32.dll")
    While 1
    Sleep ( 50 )
        For $k = 0 To 63
            If _IsPressed($key[0][$k], $dll) Then
                GUICtrlSetData($file, $key[2][$k])
                $ok[0] = 1
            EndIf
        Next
        If $ok[0] = 1 Then
            ExitLoop
        EndIf
    WEnd
    DllClose($dll)
EndFunc

$key[0][0] is the hex for key _IsPressed

$key[1][0] is the key send value (for the hotkey config used in another part of my script)

$key[2][0] is the displayed name of the key a user sees in the config hotkey window after setting a key.

As you can see I haven't added all the keys as of yet eg: F keys and a few others, if there isn't an easier way then I'll persist with the above sloppy method.

TYIA for any advice.

Cheers

Edited by smashly
Link to comment
Share on other sites

I would suggest getting a HWND for that control. Then use GUIRegisterMessage to that control and you'll get the WM_KEYDOWN messages in a function.

It could be totally wrong, but try something like this:

GUISwitch ($file)
GUIRegisterMessage ($WM_KEYDOWN, "KeyDownFunc")

Func KeyDownFunc ($HWND, $Msg, $wParam, $lParam)
    ; Handle the keypress here
EndFunc

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Link to comment
Share on other sites

Thank you for taking the time to post an answer CoePSX , it's appreciated.

I stuck with the metod I was using with _IsPressed and all seems to have worked out fine so far.

(going to post a sample script using this method in the next couple of days, just another Hotkey Shortcut Launcher. HKL for short)

The only thing else I'd like to know is what the hex value to use with _IsPressed for keys such as:

,   .   /   \  [  ]  `  -  =
These above keys are the only keys that _IsPressed doesn't seem to cover. (All Numpad keys work , but the keyboard equivilants don't)

Any idea's on how to find the value or are they just not supported by _IsPressed function?

Any advice welcome.

TYIA

Cheers

Edited by smashly
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...