Sign in to follow this  
Followers 0
computergroove

So I am building an Autoit On Screen Keyboard

3 posts in this topic

So I decided that I needed to create an autoit keyboard that mirrors the Windows 7 Onscreen Keyboard. Below is my current source. I am having trouble deciding how to do a couple of things:

1. Is there a way to make a key switch its case (both visually and when it is pressed) by hitting the shift key on the virtual keyboard?

2. The guicreate window is always on top right now but how do I make the keyboard show on the screen but send the characters presses to the program I want to type into?

3. Can I set the width and height of each key so that when I am adjusting the size of the keyboard onscreen gui window that the keys will conform to the new size (compress or expand) including the font size?

Screenshot:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1_1 = GUICreate("Form1", 1010, 308, 6, 77, -1, $WS_EX_TOPMOST)
GUISetFont(12, 400, 0, "MS Sans Serif")
$Esc = GUICtrlCreateButton("Esc", 3, 8, 73, 49)
$tilde = GUICtrlCreateButton("`", 81, 8, 51, 49)
GUICtrlSetFont(-1, 28, 400, 0, "Times New Roman")
$one = GUICtrlCreateButton("1", 136, 8, 51, 49)
$two = GUICtrlCreateButton("2", 192, 8, 51, 49)
$three = GUICtrlCreateButton("3", 248, 8, 51, 49)
$four = GUICtrlCreateButton("4", 304, 8, 51, 49)
$five = GUICtrlCreateButton("5", 360, 8, 51, 49)
$six = GUICtrlCreateButton("6", 416, 8, 51, 49)
$seven = GUICtrlCreateButton("7", 472, 8, 51, 49)
$eight = GUICtrlCreateButton("8", 528, 8, 51, 49)
$nine = GUICtrlCreateButton("9", 584, 8, 51, 49)
$zero = GUICtrlCreateButton("0", 640, 8, 51, 49)
$Minus = GUICtrlCreateButton("-", 696, 8, 51, 49)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
$equals = GUICtrlCreateButton("=", 752, 8, 51, 49)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Bksp = GUICtrlCreateButton("Bksp", 808, 8, 75, 49)
$Home = GUICtrlCreateButton("Home", 896, 8, 51, 49)
$PgUp = GUICtrlCreateButton("PgUp", 952, 8, 51, 49)
$Tab = GUICtrlCreateButton("Tab", 3, 64, 96, 49)
$q = GUICtrlCreateButton("q", 104, 64, 51, 49)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$w = GUICtrlCreateButton("w", 160, 64, 51, 49)
$e = GUICtrlCreateButton("e", 216, 64, 51, 49)
$r = GUICtrlCreateButton("r", 272, 64, 51, 49)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$t = GUICtrlCreateButton("t", 328, 64, 51, 49)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$y = GUICtrlCreateButton("y", 384, 64, 51, 49)
$u = GUICtrlCreateButton("u", 440, 64, 51, 49)
$i = GUICtrlCreateButton("i", 496, 64, 51, 49)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$o = GUICtrlCreateButton("o", 552, 64, 51, 49)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$p = GUICtrlCreateButton("p", 608, 64, 51, 49)
$LeftBracket = GUICtrlCreateButton("[", 664, 64, 51, 49)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$RightBracket = GUICtrlCreateButton("]", 720, 64, 51, 49)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Del = GUICtrlCreateButton("Del", 832, 64, 51, 49)
$End = GUICtrlCreateButton("End", 896, 64, 51, 49)
$PgDn = GUICtrlCreateButton("PgDn", 952, 64, 51, 49)
$Caps = GUICtrlCreateButton("Caps", 3, 120, 120, 49)
$ShiftLeft = GUICtrlCreateButton("Shift", 3, 176, 152, 49)
$CtrlLeft = GUICtrlCreateButton("Ctrl", 3, 232, 80, 49)
$Pause = GUICtrlCreateButton("Pause", 952, 120, 51, 49)
$Insert = GUICtrlCreateButton("Insert", 896, 120, 51, 49)
$a = GUICtrlCreateButton("a", 128, 120, 51, 49)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$s = GUICtrlCreateButton("s", 184, 120, 51, 49)
$d = GUICtrlCreateButton("d", 240, 120, 51, 49)
$f = GUICtrlCreateButton("f", 296, 120, 51, 49)
$g = GUICtrlCreateButton("g", 352, 120, 51, 49)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$h = GUICtrlCreateButton("h", 408, 120, 51, 49)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$j = GUICtrlCreateButton("j", 464, 120, 51, 49)
$k = GUICtrlCreateButton("k", 520, 120, 51, 49)
$l = GUICtrlCreateButton("l", 576, 120, 51, 49)
$Semicolon = GUICtrlCreateButton(";", 632, 120, 51, 49)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
$apostrophe = GUICtrlCreateButton("'", 688, 120, 51, 49)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Enter = GUICtrlCreateButton("Enter", 744, 120, 139, 49)
$PrtScn = GUICtrlCreateButton("PrtScn", 896, 176, 51, 49)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$ScrLk = GUICtrlCreateButton("ScrLk", 952, 176, 51, 49)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$z = GUICtrlCreateButton("z", 160, 176, 51, 49)
$x = GUICtrlCreateButton("x", 216, 176, 51, 49)
$c = GUICtrlCreateButton("c", 272, 176, 51, 49)
$v = GUICtrlCreateButton("v", 328, 176, 51, 49)
$b = GUICtrlCreateButton("b", 384, 176, 51, 49)
$n = GUICtrlCreateButton("n", 440, 176, 51, 49)
$m = GUICtrlCreateButton("m", 496, 176, 51, 49)
$comma = GUICtrlCreateButton(",", 552, 176, 51, 49)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
$period = GUICtrlCreateButton(".", 608, 176, 51, 49)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
$ForwardSlash = GUICtrlCreateButton("/", 664, 176, 51, 49)
$ShiftRight = GUICtrlCreateButton("Shift", 776, 176, 107, 49)
$WindowsButton = GUICtrlCreateButton("Win.", 88, 232, 51, 49)
$AltLeft = GUICtrlCreateButton("Alt", 144, 232, 51, 49)
$SpaceBar = GUICtrlCreateButton("", 200, 232, 291, 49)
$Function = GUICtrlCreateButton("Fn", 832, 232, 51, 49)
$options = GUICtrlCreateButton("Options", 896, 232, 51, 49)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Help = GUICtrlCreateButton("Help", 952, 232, 51, 49)
$Up = GUICtrlCreateButton("Up", 720, 176, 51, 49)
$Right = GUICtrlCreateButton("Right", 776, 232, 51, 49)
$Down = GUICtrlCreateButton("Down", 720, 232, 51, 49)
$Left = GUICtrlCreateButton("Left", 664, 232, 51, 49)
$CtrlRight = GUICtrlCreateButton("Ctrl", 608, 232, 51, 49)
$PageOptions = GUICtrlCreateButton("Page Opt.", 552, 232, 51, 49)
$AltRight = GUICtrlCreateButton("Alt", 496, 232, 51, 49)
$BackSlash = GUICtrlCreateButton("\", 776, 64, 51, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Esc
            Send("{ESC}")
        Case $tilde
            Send("`")
        Case $one
            Send("1")
        Case $two
            Send("2")
        Case $three
            Send("3")
        Case $four
            Send("4")
        Case $five
            Send("5")
        Case $six
            Send("6")
        Case $seven
            Send("7")
        Case $eight
            Send("8")
        Case $nine
            Send("9")
        Case $zero
            Send("0")
        Case $Minus
            Send("-")
        Case $Equals
            Send("=")
        Case $Bksp
            Send("{BACKSPACE}")
        Case $Home
            Send("{HOME}")
        Case $PgUp
            Send("{PGUP}")
        Case $Tab
            Send("{TAB}")
        Case $q
            Send("q")
        Case $w
            Send("w")
        Case $e
            Send("e")
        Case $r
            Send("r")
        Case $t
            Send("t")
        Case $y
            Send("y")
        Case $u
            Send("u")
        Case $i
            Send("i")
        Case $o
            Send("o")
        Case $p
            Send("p")
        Case $LeftBracket
            Send("[")
        Case $RightBracket
            Send("]")
        Case $Del
            Send("{DEL}")
        Case $End
            Send("{END}")
        Case $PgDn
            Send("{PGDN}")
        Case $Caps
            Send("{CAPSLOCK}")
        Case $ShiftLeft
            Send("{LSHIFT}")
        Case $CtrlLeft
            Send("{LCTRL}")
        Case $Pause
            Send("{PAUSE}")
        Case $Insert
            Send("{INS}")
        Case $a
            Send("a")
        Case $s
            Send("s")
        Case $d
            Send("d")
        Case $f
            Send("f")
        Case $g
            Send("g")
        Case $h
            Send("h")
        Case $j
            Send("j")
        Case $k
            Send("k")
        Case $l
            Send("l")
        Case $Semicolon
            Send(";")
        Case $apostrophe
            Send("'")
        Case $Enter
            Send("{ENTER}")
        Case $PrtScn
            Send("{PRINTSCREEN}")
        Case $ScrLk
            Send("{SCROLLLOCK}")
        Case $z
            Send("z")
        Case $x
            Send("x")
        Case $c
            Send("c")
        Case $v
            Send("v")
        Case $b
            Send("b")
        Case $n
            Send("n")
        Case $m
            Send("m")
        Case $comma
            Send(",")
        Case $period
            Send(".")
        Case $ForwardSlash
            Send("/")
        Case $ShiftRight
            Send("{RSHIFT}")
        Case $WindowsButton
            Send("{LWIN}")
        Case $AltLeft
            Send("{LALT}")
        Case $SpaceBar
            Send(" ")
        Case $Function
            Send("")
        Case $options
            Send("")
        Case $Help
            Send("")
        Case $Up
            Send("{UP}")
        Case $Right
            Send("{RIGHT}")
        Case $Down
            Send("{DOWN}")
        Case $Left
            Send("{LEFT}")
        Case $CtrlRight
            Send("{RCTRL}")
        Case $PageOptions
            Send("{}")
        Case $AltRight
            Send("{RALT}")
        Case $BackSlash
            Send("\")
    EndSwitch
WEnd

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

Share this post


Link to post
Share on other sites



Maybe this gives you some ideas:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
Global $bShiftPressed=False
Global $hWnd="[CLASS:Notepad]"

$hGUI = GUICreate("hGUI", 173, 50, -1, @DesktopHeight-200, -1, $WS_EX_TOPMOST)
GUISetOnEvent($GUI_EVENT_CLOSE, "hGUIClose")

$hShift = GUICtrlCreateButton("Shift", 8, 8, 75, 33)
GUICtrlSetOnEvent(-1, "_Shift")

Local $hA = GUICtrlCreateButton("a", 88, 8, 75, 33)
GUICtrlSetOnEvent(-1, "hAClick")
GUISetState(@SW_SHOW)
;test
Run("notepad.exe")

While 1
    Sleep(100)
WEnd

Func hAClick()
    Local $hW
    $hW=WinGetHandle($hWnd)
    WinSetOnTop($hW,"",0)
    WinActivate($hW,"")
    Send("a")
EndFunc

Func _Shift()
    Local $sShift
    Switch $bShiftPressed
        Case False
            $bShiftPressed=True
            GUICtrlSetData($hA,"A")
            $sShift=Send("{SHIFTDOWN}")
            ConsoleWrite($bShiftPressed&@LF)
        Case Else
            $bShiftPressed=False
            GUICtrlSetData($hA,"a")
            $sShift=Send("{SHIFTUP}")
            ConsoleWrite($bShiftPressed&@LF)
    EndSwitch
    Return $sShift
EndFunc

Func hGUIClose()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

3. Can I set the width and height of each key so that when I am adjusting the size of the keyboard onscreen gui window that the keys will conform to the new size (compress or expand) including the font size?

Use these in your script:

GUICtrlSetResizing

WinMove

Edited by JoHanatCent

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