Sign in to follow this  
Followers 0
BitByteBit

Printing keys to ToolTip

2 posts in this topic

#1 ·  Posted (edited)

I wanted a ToolTip to display a search term in real time,waiting until ,the result would be used later to search iTunes. I did it, but a really long way.

Wondering if anybody could show me a more efficient way?

Here was my solution:

#include<array.au3>
#include<misc.au3>
Global $Keys[1][2] = [[0, 0]]
Keys()
Search1()
Func Search1() ;Catch KeyPresses
    $Search = ""
    While Not _IsPressed("0D") ;or _IsPressed("1B") ;Wait for enter
        ToolTip("Search: " & $Search) ;Display Search Term
        #Region 0-9 A-Z
        If _IsPressed($Keys[1][0]) Then $Search = $Search & $Keys[1][1] ;If 0 is presses then $Search = 0
        While _IsPressed($Keys[1][0])
                Sleep(2)
        WEnd
        If _IsPressed($Keys[2][0]) Then $Search = $Search & $Keys[2][1] ;1
        While _IsPressed($Keys[2][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[3][0]) Then $Search = $Search & $Keys[3][1] ;2
        While _IsPressed($Keys[3][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[4][0]) Then $Search = $Search & $Keys[4][1]
        While _IsPressed($Keys[4][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[5][0]) Then $Search = $Search & $Keys[5][1]
        While _IsPressed($Keys[5][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[6][0]) Then $Search = $Search & $Keys[6][1]
        While _IsPressed($Keys[6][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[7][0]) Then $Search = $Search & $Keys[7][1]
        While _IsPressed($Keys[7][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[8][0]) Then $Search = $Search & $Keys[8][1]
        While _IsPressed($Keys[8][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[9][0]) Then $Search = $Search & $Keys[9][1]
        While _IsPressed($Keys[9][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[10][0]) Then $Search = $Search & $Keys[10][1]
        While _IsPressed($Keys[10][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[11][0]) Then $Search = $Search & $Keys[11][1] ;A
        While _IsPressed($Keys[11][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[12][0]) Then $Search = $Search & $Keys[12][1]
        While _IsPressed($Keys[12][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[13][0]) Then $Search = $Search & $Keys[13][1]
        While _IsPressed($Keys[13][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[14][0]) Then $Search = $Search & $Keys[14][1]
        While _IsPressed($Keys[14][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[15][0]) Then $Search = $Search & $Keys[15][1]
        While _IsPressed($Keys[15][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[16][0]) Then $Search = $Search & $Keys[16][1]
        While _IsPressed($Keys[16][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[17][0]) Then $Search = $Search & $Keys[17][1]
        While _IsPressed($Keys[17][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[18][0]) Then $Search = $Search & $Keys[18][1]
        While _IsPressed($Keys[18][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[19][0]) Then $Search = $Search & $Keys[19][1]
        While _IsPressed($Keys[19][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[20][0]) Then $Search = $Search & $Keys[20][1]
        While _IsPressed($Keys[20][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[21][0]) Then $Search = $Search & $Keys[21][1]
        While _IsPressed($Keys[21][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[22][0]) Then $Search = $Search & $Keys[22][1]
        While _IsPressed($Keys[22][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[23][0]) Then $Search = $Search & $Keys[23][1] ;M
        While _IsPressed($Keys[23][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[24][0]) Then $Search = $Search & $Keys[24][1]
        While _IsPressed($Keys[24][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[25][0]) Then $Search = $Search & $Keys[25][1]
        While _IsPressed($Keys[25][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[26][0]) Then $Search = $Search & $Keys[26][1]
        While _IsPressed($Keys[26][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[27][0]) Then $Search = $Search & $Keys[27][1]
        While _IsPressed($Keys[27][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[28][0]) Then $Search = $Search & $Keys[28][1]
        While _IsPressed($Keys[28][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[29][0]) Then $Search = $Search & $Keys[29][1]
        While _IsPressed($Keys[29][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[30][0]) Then $Search = $Search & $Keys[30][1]
        While _IsPressed($Keys[30][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[31][0]) Then $Search = $Search & $Keys[31][1]
        While _IsPressed($Keys[31][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[32][0]) Then $Search = $Search & $Keys[32][1]
        While _IsPressed($Keys[32][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[33][0]) Then $Search = $Search & $Keys[33][1]
        While _IsPressed($Keys[33][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[34][0]) Then $Search = $Search & $Keys[34][1]
        While _IsPressed($Keys[34][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[35][0]) Then $Search = $Search & $Keys[35][1]
        While _IsPressed($Keys[35][0])
            Sleep(2)
        WEnd
        If _IsPressed($Keys[36][0]) Then $Search = $Search & $Keys[36][1];Z
        While _IsPressed($Keys[36][0])
            Sleep(2)
        WEnd
        ;If _IsPressed($Keys[37][0]) Then $Search = $Search & $Keys[37][1] ;Escape
        ;While _IsPressed($Keys[37][0])
    ;       Sleep(2)
    ;   WEnd
        #EndRegion 0-9 A-Z

        If _IsPressed("08") Then ;BackSpace
            $Search = StringTrimRight($Search, 1);Remove last character
            Sleep(75)
        EndIf

        If _IsPressed("20") Then $Search = $Search & " " ;SpaceBar
        While _IsPressed("20")
            Sleep(2)
        WEnd

        If _IsPressed("1B") Then ;Escape exits loop
            While _IsPressed("1B")
                Sleep(2)
            WEnd
            ToolTip("You cancelled the search")
            Sleep(1250)
            ToolTip("")
            $Cancel = True
            ExitLoop
        EndIf

        Sleep(25)
        $Search = _StringProper($Search)

    WEnd
    ToolTip("")
EndFunc   ;==>Search1

Func Keys()

    ;Creates a 2d array, in which the first column contains the Hex Key for _IsPressed and the second column is the key in lower case
    $Clip = "30 0 key31 1 key32 2 key33 3 key34 4 key35 5 key36 6 key37 7 key38 8 key39 9 key41 a key42 b key43 c key44 d key45 e key46 f key47 g key48 h key49 i key4a j key4b k key4c l key4d m key4e n key4f o key50 p key51 q key52 r key53 s key54 t key55 u key56 v key57 w key58 x key59 y key5a z key1B Escape key"
    $String = StringSplit($Clip, " key", 1)
    For $x = 0 To $String[0]
        $KeyHex = StringSplit($String[$x], " ")
        If Not @error Then
            ReDim $Keys[UBound($Keys, 1) + 1][2] ; Resize Array
            $iElement = UBound($Keys, 1) - 1
            $Keys[$iElement][0] = $KeyHex[1] ;Hex Key
            $Keys[$iElement][1] = $KeyHex[2] ;Corresponding key
            $Keys[0][0] = $iElement ; number of records in the array
        EndIf
    Next
    _ArrayDisplay($Keys)
EndFunc   ;==>Keys
Edited by BitByteBit

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

What is wrong with just typing into an input?

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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