Sign in to follow this  
Followers 0
mike1234

Onscreen Keyboard

2 posts in this topic

So heres my on screen keyboard didnt really spend that much time on it (doesnt have a spacebar, backspace etc yet). Any suggestions on parsing out what button was clicked (FunKey)? I like how short it is but I'm not sure if there will be a situation in which the control IDs might change.

Any suggestions for a more effecient keyboard?

#include <GuiConstants.au3>
#include <windowsconstants.au3>
Opt("GUIOnEventMode", 1)


$keyboardwidth = 850
$keyboardheight = 650
$buffer = 20
$keybuffer = 20
$keyboardlocx = 20
$keyboardlocy = 200
$font = "Bodoni MT Black"
$fontsize = 60
$fontcolor = 0xffffff
$keywidth = $keyboardwidth/11
$keyheight = $keyboardheight/6
$row1 = "Q-W-E-R-T-Y-U-I-O-P"
$row2 = "A-S-D-F-G-H-J-K-L"
$row3 = "Z-X-C-V-B-N-M"
$keys = "0-1-2-3-4-5-6-7-8-9-Q-W-E-R-T-Y-U-I-O-P-A-S-D-F-G-H-J-K-L-Z-X-C-V-B-N-M"
$controls = 2 ;number of control IDs registered

$row1array = StringSplit($row1,"-")
$row2array = StringSplit($row2,"-")
$row3array = StringSplit($row3,"-")
$keyarray = StringSplit($keys,"-")


    GUISetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

    $pos = MouseGetPos()
    $keyboard = GUICreate("Keyboard", $keyboardwidth + 10*$buffer,$keyboardheight + 4*$buffer,$keyboardlocx,$keyboardlocy, $WS_POPUP);$WS_EX_TOPMOST

    GUISetFont(20, 400, 4, $font) 
    $i = 0
    While $i < 10
        GUICtrlCreateButton($i,$i*$keywidth,0,$keywidth,$keyheight)
        GUICtrlSetOnEvent(-1,"FunKey")
        $i = $i+1
    Wend

    $i = 1
    While $i < $row1array[0]+1
        GUICtrlCreateButton($row1array[$i],$i*$keywidth-$keywidth,$keyheight,$keywidth,$keyheight)
        GUICtrlSetOnEvent(-1,"FunKey")
        $i = $i+1
    Wend

    $i = 1
    While $i < $row2array[0]+1
        GUICtrlCreateButton($row2array[$i],$i*$keywidth-$keywidth*.5,$keyheight*2,$keywidth,$keyheight)
        GUICtrlSetOnEvent(-1,"FunKey")
        $i = $i+1
    Wend

    $i = 1
    While $i < $row3array[0]+1
        GUICtrlCreateButton($row3array[$i],$i*$keywidth,$keyheight*3,$keywidth,$keyheight)
        GUICtrlSetOnEvent(-1,"FunKey")
        $i = $i+1
    Wend

    GUISetState(@SW_SHOW)
    GUISetControlsVisible($keyboard)


While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd


Func FunKey()
    Msgbox(0,"",$keyarray[@GUI_CtrlId - $controls])

EndFunc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func GUISetControlsVisible($hWnd)
    Local $aClassList, $aM_Mask, $aCtrlPos, $aMask

    $aClassList = StringSplit(_WinGetClassListEx($hWnd), @LF)
    $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)

    For $i = 1 To UBound($aClassList) - 1
        $aCtrlPos = ControlGetPos($hWnd, '', $aClassList[$i])
        If Not IsArray($aCtrlPos) Then ContinueLoop

        $aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", _
            "long", $aCtrlPos[0], _
            "long", $aCtrlPos[1], _
            "long", $aCtrlPos[0] + $aCtrlPos[2], _
            "long", $aCtrlPos[1] + $aCtrlPos[3])
        DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
    Next
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWnd, "long", $aM_Mask[0], "int", 1)
EndFunc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _WinGetClassListEx($sTitle)
    Local $sClassList = WinGetClassList($sTitle)
    Local $aClassList = StringSplit($sClassList, @LF)
    Local $sRetClassList = "", $sHold_List = "|"
    Local $aiInHold, $iInHold

    For $i = 1 To UBound($aClassList) - 1
        If $aClassList[$i] = "" Then ContinueLoop

        If StringRegExp($sHold_List, "\|" & $aClassList[$i] & "~(\d+)\|") Then
            $aiInHold = StringRegExp($sHold_List, ".*\|" & $aClassList[$i] & "~(\d+)\|.*", 1)
            $iInHold = Number($aiInHold[UBound($aiInHold)-1])

            If $iInHold = 0 Then $iInHold += 1

            $aClassList[$i] &= "~" & $iInHold + 1
            $sHold_List &= $aClassList[$i] & "|"

            $sRetClassList &= $aClassList[$i] & @LF
        Else
            $aClassList[$i] &= "~1"
            $sHold_List &= $aClassList[$i] & "|"
            $sRetClassList &= $aClassList[$i] & @LF
        EndIf
    Next

    Return StringReplace(StringStripWS($sRetClassList, 3), "~", "")
EndFunc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Share this post


Link to post
Share on other sites



Not closely related, but you may be interessed to discover Dasher if you don't already know it: a completely different way to enter text without keyboard. And it really works!


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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