Jump to content
Sign in to follow this  
Kreatorul

Send, control send

Recommended Posts

Kreatorul

How can I send key to any window behind the gui...I am making a on-screen keyboard and when i press a button it sends a key but i need to send the key to the active window behind the gui...If i use send it sends to the curently active window...gui... :):P If I use control Send I have to send keys to a specific window...so it's not good :D

Share this post


Link to post
Share on other sites
lod3n

Here, try this:

#include <GUIConstants.au3>
global $dll = DllOpen("user32.dll")

$gui = GUICreate("Keyboard")
$bA = GUICtrlCreateButton ("A",  10, 30, 100)
WinSetOnTop($gui,"",1)
GUISetState (@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        case $GUI_EVENT_CLOSE
            ExitLoop
        case $bA
            type("A")
    EndSwitch
Wend
DllClose($dll)

Func type($chars)
    winactivate(lastwindow())
    send($chars)
EndFunc

func lastwindow()   
    $var = WinList()
    For $i = 1 to $var[0][0]
      ; Only display visble windows that have a title
      If $var[$i][0] <> "" AND IsVisible($var[$i][1]) AND NOT IsOntop($var[$i][1]) Then exitloop
    Next
    ;return $var[$i][0] ; returns the window name
    return $var[$i][1] ; returns the window handle - much better
endfunc

   
Func IsVisible($handle) ; required for lastwindow()
  If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc


func IsOntop($handle)
  $aEStyle = DllCall($dll, "long", "GetWindowLong", "hwnd", $handle, "int", -20)
  ; above borrowed from AnyGui code - thanks Quaizywabbit
  If BitAnd($aEStyle[0], 8 ) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc

Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites
Kreatorul

I'm still working on this...but hope you get what I want

#include <GUIConstants.au3>
; Variables
$Form1 = GUICreate("AForm1", 570, 215, 210, 348)
$menu=GuiCtrlCreateMenu("File")
$menu1=GuiCtrlCreateMenuItem("Exit", $menu)
$Esc = GUICtrlCreateButton("Esc", 5, 30, 25, 25)
$F1 = GUICtrlCreateButton("F1", 45, 30, 25, 25)
$F2 = GUICtrlCreateButton("F2", 69, 30, 25, 25)
$F3 = GUICtrlCreateButton("F3", 93, 30, 25, 25)
$F4 = GUICtrlCreateButton("F4", 117, 30, 25, 25)
$F5 = GUICtrlCreateButton("F5", 157, 30, 25, 25)
$F6 = GUICtrlCreateButton("F6", 181, 30, 25, 25)
$F7 = GUICtrlCreateButton("F7", 205, 30, 25, 25)
$F8 = GUICtrlCreateButton("F8", 229, 30, 25, 25)
$F9 = GUICtrlCreateButton("F9", 269, 30, 25, 25)
$F10 = GUICtrlCreateButton("F10", 293, 30, 25, 25)
$F11 = GUICtrlCreateButton("F11", 317, 30, 25, 25)
$F12 = GUICtrlCreateButton("F12", 341, 30, 25, 25)
$Print = GUICtrlCreateButton("PSc", 381, 30, 25, 25)
$Scroll = GUICtrlCreateButton("ScL", 405, 30, 25, 25)
$pause = GUICtrlCreateButton("PBr", 429, 30, 25, 25)
$cr = GUICtrlCreateButton("` ~", 5, 70, 25, 25)
$b1 = GUICtrlCreateButton("1 !", 29, 70, 25, 25)
$b2 = GUICtrlCreateButton("2 @", 53, 70, 25, 25)
$b3 = GUICtrlCreateButton("3 #", 77, 70, 25, 25)
$b4 = GUICtrlCreateButton("4 $", 101, 70, 25, 25)
$b5 = GUICtrlCreateButton("5 %", 125, 70, 25, 25)
$b6 = GUICtrlCreateButton("6 ^", 149, 70, 25, 25)
$b7 = GUICtrlCreateButton("7 &", 173, 70, 25, 25)
$b8 = GUICtrlCreateButton("8 *", 197, 70, 25, 25)
$b9 = GUICtrlCreateButton("9 (", 221, 70, 25, 25)
$b0 = GUICtrlCreateButton("0 )", 245, 70, 25, 25)
$bl = GUICtrlCreateButton("- _", 269, 70, 25, 25)
$bpl = GUICtrlCreateButton("+ =", 293, 70, 25, 25)
$bl2 = GUICtrlCreateButton("\ |", 317, 70, 25, 25)
$bk = GUICtrlCreateButton("<---", 341, 70, 25, 25)
$ins = GUICtrlCreateButton("Ins", 381, 70, 25, 25)
$ho = GUICtrlCreateButton("Ho", 405, 70, 25, 25)
$pgu = GUICtrlCreateButton("PgU", 429, 70, 25, 25)
$del = GUICtrlCreateButton("Del", 381, 94, 25, 25)
$end = GUICtrlCreateButton("End", 405, 94, 25, 25)
$PgD = GUICtrlCreateButton("PgD", 429, 94, 25, 25)
$tab = GUICtrlCreateButton("Tab", 5, 94, 33, 25)
$Q = GUICtrlCreateButton("Q", 37, 94, 25, 25)
$W = GUICtrlCreateButton("W", 61, 94, 25, 25)
$E = GUICtrlCreateButton("E", 85, 94, 25, 25)
$R = GUICtrlCreateButton("R", 109, 94, 25, 25)
$T = GUICtrlCreateButton("T", 133, 94, 25, 25)
$Y = GUICtrlCreateButton("Y", 157, 94, 25, 25)
$U = GUICtrlCreateButton("U", 181, 94, 25, 25)
$I = GUICtrlCreateButton("I", 205, 94, 25, 25)
$O = GUICtrlCreateButton("O", 229, 94, 25, 25)
$p = GUICtrlCreateButton("P", 253, 94, 25, 25)
$bp = GUICtrlCreateButton("[ {", 277, 94, 25, 25)
$bp2 = GUICtrlCreateButton("] }", 301, 94, 25, 25)
$enter1 = GUICtrlCreateButton("Enter", 325, 94, 41, 25)
$caps = GUICtrlCreateButton("Caps", 5, 118, 41, 25)
$A = GUICtrlCreateButton("A", 45, 118, 25, 25)
$ButtonS = GUICtrlCreateButton("S", 69, 118, 25, 25)
$ButtonD = GUICtrlCreateButton("D", 93, 118, 25, 25)
$ButtonF = GUICtrlCreateButton("F", 117, 118, 25, 25)
$G = GUICtrlCreateButton("G", 141, 118, 25, 25)
$H = GUICtrlCreateButton("H", 165, 118, 25, 25)
$J = GUICtrlCreateButton("J", 189, 118, 25, 25)
$K = GUICtrlCreateButton("K", 213, 118, 25, 25)
$L = GUICtrlCreateButton("L", 237, 118, 25, 25)
$bpsv = GUICtrlCreateButton("; :", 261, 118, 25, 25)
$bcrt = GUICtrlCreateButton("' ''", 285, 118, 25, 25)
$enter = GUICtrlCreateButton("Enter", 309, 118, 57, 25)
$Shift = GUICtrlCreateButton("Shift", 5, 142, 57, 25)
$Z = GUICtrlCreateButton("Z", 61, 142, 25, 25)
$X = GUICtrlCreateButton("X", 85, 142, 25, 25)
$C = GUICtrlCreateButton("C", 109, 142, 25, 25)
$V = GUICtrlCreateButton("V", 133, 142, 25, 25)
$B = GUICtrlCreateButton("B", 157, 142, 25, 25)
$n = GUICtrlCreateButton("N", 181, 142, 25, 25)
$m = GUICtrlCreateButton("M", 205, 142, 25, 25)
$bvir = GUICtrlCreateButton(", <", 229, 142, 25, 25)
$bpu = GUICtrlCreateButton(". >", 253, 142, 25, 25)
$bpl2 = GUICtrlCreateButton("/ ?", 277, 142, 25, 25)
$shift1 = GUICtrlCreateButton("Shift", 301, 142, 65, 25)
$ctrl = GUICtrlCreateButton("Ctrl", 5, 166, 33, 25)
$Win = GUICtrlCreateButton("Win", 37, 166, 33, 25)
$Alt = GUICtrlCreateButton("Alt", 69, 166, 33, 25)
$Ctrl1 = GUICtrlCreateButton("Ctrl", 333, 166, 33, 25)
$win2 = GUICtrlCreateButton("Win", 301, 166, 33, 25)
$alt1 = GUICtrlCreateButton("Alt", 269, 166, 33, 25)
$space = GUICtrlCreateButton("Space", 101, 166, 169, 25)
$left = GUICtrlCreateButton("<--", 381, 166, 25, 25)
$up = GUICtrlCreateButton("/\", 405, 142, 25, 25)
$down = GUICtrlCreateButton("\/", 405, 166, 25, 25)
$right = GUICtrlCreateButton("-->", 429, 166, 25, 25)
$Button21 = GUICtrlCreateButton("Num", 469, 70, 25, 25)
$bld = GUICtrlCreateButton("/", 493, 70, 25, 25)
$bst = GUICtrlCreateButton("*", 517, 70, 25, 25)
$Button22 = GUICtrlCreateButton("-", 541, 70, 25, 25)
$b77 = GUICtrlCreateButton("7", 469, 94, 25, 25)
$b88 = GUICtrlCreateButton("8", 493, 94, 25, 25)
$b99 = GUICtrlCreateButton("9", 517, 94, 25, 25)
$Button23 = GUICtrlCreateButton("4", 469, 118, 25, 25)
$b55 = GUICtrlCreateButton("5", 493, 118, 25, 25)
$b66 = GUICtrlCreateButton("6", 517, 118, 25, 25)
$b11 = GUICtrlCreateButton("1", 469, 142, 25, 25)
$b22 = GUICtrlCreateButton("2", 493, 142, 25, 25)
$b33 = GUICtrlCreateButton("3", 517, 142, 25, 25)
$Button24 = GUICtrlCreateButton("0", 469, 166, 49, 25)
$Button25 = GUICtrlCreateButton(".", 517, 166, 25, 25)
$Button26 = GUICtrlCreateButton("+", 541, 94, 25, 49)
$Button27 = GUICtrlCreateButton("Ent", 541, 142, 25, 49)
GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;;;;;
EndSelect
If $msg=$menu1 Then ExitLoop
If $msg=$esc Then Send("{ESC}")
If $msg=$f1 Then Send("{F1}")
If $msg=$f2 Then Send("{F2}")
If $msg=$f3 Then Send("{F3}")
If $msg=$f4 Then Send("{F4}")
If $msg=$f5 Then Send("{F5}")
If $msg=$f6 Then Send("{F6}")
If $msg=$f7 Then Send("{F7}")
If $msg=$f8 Then Send("{F8}")
If $msg=$f9 Then Send("{F9}")
If $msg=$f10 Then Send("{F10}")
If $msg=$f11 Then Send("{F11}")
If $msg=$f12 Then Send("{F12}")
If $msg=$print Then Send("{PRINTSCREEN}")
If $msg=$scroll Then Send("{SCROLLLOCK toggle}")
If $msg=$pause Then Send("{CTRLBREAK}")
If $msg=$cr Then Send("`")
WEnd
Exit

Share this post


Link to post
Share on other sites
lod3n

Here you go. You still need to hook up all of the keys in the Type function, but I don't have time at the moment. Only A and B work right now.

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode 
global $dll = DllOpen("user32.dll")
global $shiftT = 0
global $ctrlT = 0
global $WinT = 0
global $AltT = 0



$gui = GUICreate("Keyboard", 570, 215, 210, 348)
$menu=GuiCtrlCreateMenu("File")
$menu1=GuiCtrlCreateMenuItem("Exit", $menu)
$Esc = GUICtrlCreateButton("Esc", 5, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F1 = GUICtrlCreateButton("F1", 45, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F2 = GUICtrlCreateButton("F2", 69, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F3 = GUICtrlCreateButton("F3", 93, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F4 = GUICtrlCreateButton("F4", 117, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F5 = GUICtrlCreateButton("F5", 157, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F6 = GUICtrlCreateButton("F6", 181, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F7 = GUICtrlCreateButton("F7", 205, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F8 = GUICtrlCreateButton("F8", 229, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F9 = GUICtrlCreateButton("F9", 269, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F10 = GUICtrlCreateButton("F10", 293, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F11 = GUICtrlCreateButton("F11", 317, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F12 = GUICtrlCreateButton("F12", 341, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Print = GUICtrlCreateButton("PSc", 381, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Scroll = GUICtrlCreateButton("ScL", 405, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$pause = GUICtrlCreateButton("PBr", 429, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$cr = GUICtrlCreateButton("` ~", 5, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b1 = GUICtrlCreateButton("1 !", 29, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b2 = GUICtrlCreateButton("2 @", 53, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b3 = GUICtrlCreateButton("3 #", 77, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b4 = GUICtrlCreateButton("4 $", 101, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b5 = GUICtrlCreateButton("5 %", 125, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b6 = GUICtrlCreateButton("6 ^", 149, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b7 = GUICtrlCreateButton("7 &", 173, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b8 = GUICtrlCreateButton("8 *", 197, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b9 = GUICtrlCreateButton("9 (", 221, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b0 = GUICtrlCreateButton("0 )", 245, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bl = GUICtrlCreateButton("- _", 269, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bpl = GUICtrlCreateButton("+ =", 293, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bl2 = GUICtrlCreateButton("\ |", 317, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bk = GUICtrlCreateButton("<---", 341, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$ins = GUICtrlCreateButton("Ins", 381, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$ho = GUICtrlCreateButton("Ho", 405, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$pgu = GUICtrlCreateButton("PgU", 429, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$del = GUICtrlCreateButton("Del", 381, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$end = GUICtrlCreateButton("End", 405, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$PgD = GUICtrlCreateButton("PgD", 429, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$tab = GUICtrlCreateButton("Tab", 5, 94, 33, 25)
GUICtrlSetOnEvent(-1, "type")
$Q = GUICtrlCreateButton("Q", 37, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$W = GUICtrlCreateButton("W", 61, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$E = GUICtrlCreateButton("E", 85, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$R = GUICtrlCreateButton("R", 109, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$T = GUICtrlCreateButton("T", 133, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Y = GUICtrlCreateButton("Y", 157, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$U = GUICtrlCreateButton("U", 181, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$I = GUICtrlCreateButton("I", 205, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$O = GUICtrlCreateButton("O", 229, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$p = GUICtrlCreateButton("P", 253, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bp = GUICtrlCreateButton("[ {", 277, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bp2 = GUICtrlCreateButton("] }", 301, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$enter1 = GUICtrlCreateButton("Enter", 325, 94, 41, 25)
GUICtrlSetOnEvent(-1, "type")
$caps = GUICtrlCreateButton("Caps", 5, 118, 41, 25)
GUICtrlSetOnEvent(-1, "toggle")
$A = GUICtrlCreateButton("A", 45, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$ButtonS = GUICtrlCreateButton("S", 69, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$ButtonD = GUICtrlCreateButton("D", 93, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$ButtonF = GUICtrlCreateButton("F", 117, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$G = GUICtrlCreateButton("G", 141, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$H = GUICtrlCreateButton("H", 165, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$J = GUICtrlCreateButton("J", 189, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$K = GUICtrlCreateButton("K", 213, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$L = GUICtrlCreateButton("L", 237, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bpsv = GUICtrlCreateButton("; :", 261, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bcrt = GUICtrlCreateButton("' ''", 285, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$enter = GUICtrlCreateButton("Enter", 309, 118, 57, 25)
GUICtrlSetOnEvent(-1, "type")
$Shift = GUICtrlCreateButton("Shift", 5, 142, 57, 25)
GUICtrlSetOnEvent(-1, "toggle")
$Z = GUICtrlCreateButton("Z", 61, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$X = GUICtrlCreateButton("X", 85, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$C = GUICtrlCreateButton("C", 109, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$V = GUICtrlCreateButton("V", 133, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$B = GUICtrlCreateButton("B", 157, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$n = GUICtrlCreateButton("N", 181, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$m = GUICtrlCreateButton("M", 205, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bvir = GUICtrlCreateButton(", <", 229, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bpu = GUICtrlCreateButton(". >", 253, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bpl2 = GUICtrlCreateButton("/ ?", 277, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$shift1 = GUICtrlCreateButton("Shift", 301, 142, 65, 25)
GUICtrlSetOnEvent(-1, "toggle")
$ctrl = GUICtrlCreateButton("Ctrl", 5, 166, 33, 25)
GUICtrlSetOnEvent(-1, "toggle")
$Win = GUICtrlCreateButton("Win", 37, 166, 33, 25)
GUICtrlSetOnEvent(-1, "toggle")
$Alt = GUICtrlCreateButton("Alt", 69, 166, 33, 25)
GUICtrlSetOnEvent(-1, "toggle")
$Ctrl1 = GUICtrlCreateButton("Ctrl", 333, 166, 33, 25)
GUICtrlSetOnEvent(-1, "toggle")
$win2 = GUICtrlCreateButton("Win", 301, 166, 33, 25)
GUICtrlSetOnEvent(-1, "toggle")
$alt1 = GUICtrlCreateButton("Alt", 269, 166, 33, 25)
GUICtrlSetOnEvent(-1, "toggle")
$space = GUICtrlCreateButton("Space", 101, 166, 169, 25)
GUICtrlSetOnEvent(-1, "type")
$left = GUICtrlCreateButton("<--", 381, 166, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$up = GUICtrlCreateButton("/\", 405, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$down = GUICtrlCreateButton("\/", 405, 166, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$right = GUICtrlCreateButton("-->", 429, 166, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Button21 = GUICtrlCreateButton("Num", 469, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bld = GUICtrlCreateButton("/", 493, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bst = GUICtrlCreateButton("*", 517, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Button22 = GUICtrlCreateButton("-", 541, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b77 = GUICtrlCreateButton("7", 469, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b88 = GUICtrlCreateButton("8", 493, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b99 = GUICtrlCreateButton("9", 517, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Button23 = GUICtrlCreateButton("4", 469, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b55 = GUICtrlCreateButton("5", 493, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b66 = GUICtrlCreateButton("6", 517, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b11 = GUICtrlCreateButton("1", 469, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b22 = GUICtrlCreateButton("2", 493, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b33 = GUICtrlCreateButton("3", 517, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Button24 = GUICtrlCreateButton("0", 469, 166, 49, 25)
GUICtrlSetOnEvent(-1, "type")
$Button25 = GUICtrlCreateButton(".", 517, 166, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Button26 = GUICtrlCreateButton("+", 541, 94, 25, 49)
GUICtrlSetOnEvent(-1, "type")
$Button27 = GUICtrlCreateButton("Ent", 541, 142, 25, 49)
GUICtrlSetOnEvent(-1, "type")

GUISetOnEvent($GUI_EVENT_CLOSE, "terminate")

GUISetState (@SW_SHOW)
WinSetOnTop($gui,"",1)

While 1
  Sleep(1000)   ; Just idle around 
WEnd
DllClose($dll)

func terminate()
    Exit
EndFunc


func toggle()
    consolewrite("toggle" & @crlf)
    switch @GUI_CTRLID
        case $caps
            $shiftT = not $shiftT
        case $shift
            $shiftT = not $shiftT
        case $shift1
            $shiftT = not $shiftT
        case $ctrl
            $ctrlT = not $ctrlT
        Case $Win
            $WinT = not $WinT
        Case $Alt
            $AltT = not $AltT
        Case $Ctrl1
            $CtrlT = not $CtrlT
        Case $win2
            $winT = not $winT
        Case $alt1
            $altT = not $altT
    endswitch
EndFunc


Func type()
    switch @GUI_CTRLID
        case $A
            keysend("a")
        case $b
            keysend("b")
    endswitch
EndFunc

func keysend($chars)
    if $shiftT = 1  then $chars = "+" + $chars 
    if $ctrlT = 1  then $chars = "^" + $chars
    if $WinT = 1 or $winT = 1 then $chars = "#" + $chars
    if $AltT = 1  then $chars = "!" + $chars

    winactivate(lastwindow())
    send($chars)
EndFunc

func lastwindow()   
    $var = WinList()
    For $i = 1 to $var[0][0]
      ; Only display visble windows that have a title
      If $var[$i][0] <> "" AND IsVisible($var[$i][1]) AND NOT IsOntop($var[$i][1]) Then exitloop
    Next
    ;return $var[$i][0] ; returns the window name
    consolewrite( $var[$i][0] & @crlf)
    return $var[$i][1] ; returns the window handle - much better
endfunc

   
Func IsVisible($handle) ; required for lastwindow()
  If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc


func IsOntop($handle)
  $aEStyle = DllCall($dll, "long", "GetWindowLong", "hwnd", $handle, "int", -20)
  ; above borrowed from AnyGui code - thanks Quaizywabbit
  If BitAnd($aEStyle[0], 8 ) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites
Kreatorul

10x a lot...but the only problem is ..its a little slow...if this could work a lil faster would be great...:) Many thanks :P

And caps or shift etc...not working..if pressed then it sends 0 every time a type something...sorry i couldn't understand what u did with shiftt ctrlt etc :D

Edited by Kreatorul

Share this post


Link to post
Share on other sites
lod3n

Okay, I sped it up by creating the window with the extended style WS_EX_NOACTIVATE , and I fixed the bug that was making the 0s.

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode 

global $shiftT = 0
global $ctrlT = 0
global $WinT = 0
global $AltT = 0
global $WS_EX_NOACTIVATE = 0x8000000

$gui = GUICreate("Keyboard", 570, 215, 210, 348,-1,$WS_EX_NOACTIVATE)
$menu=GuiCtrlCreateMenu("File")
$menu1=GuiCtrlCreateMenuItem("Exit", $menu)
$Esc = GUICtrlCreateButton("Esc", 5, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F1 = GUICtrlCreateButton("F1", 45, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F2 = GUICtrlCreateButton("F2", 69, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F3 = GUICtrlCreateButton("F3", 93, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F4 = GUICtrlCreateButton("F4", 117, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F5 = GUICtrlCreateButton("F5", 157, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F6 = GUICtrlCreateButton("F6", 181, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F7 = GUICtrlCreateButton("F7", 205, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F8 = GUICtrlCreateButton("F8", 229, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F9 = GUICtrlCreateButton("F9", 269, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F10 = GUICtrlCreateButton("F10", 293, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F11 = GUICtrlCreateButton("F11", 317, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$F12 = GUICtrlCreateButton("F12", 341, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Print = GUICtrlCreateButton("PSc", 381, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Scroll = GUICtrlCreateButton("ScL", 405, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$pause = GUICtrlCreateButton("PBr", 429, 30, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$cr = GUICtrlCreateButton("` ~", 5, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b1 = GUICtrlCreateButton("1 !", 29, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b2 = GUICtrlCreateButton("2 @", 53, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b3 = GUICtrlCreateButton("3 #", 77, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b4 = GUICtrlCreateButton("4 $", 101, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b5 = GUICtrlCreateButton("5 %", 125, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b6 = GUICtrlCreateButton("6 ^", 149, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b7 = GUICtrlCreateButton("7 &", 173, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b8 = GUICtrlCreateButton("8 *", 197, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b9 = GUICtrlCreateButton("9 (", 221, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b0 = GUICtrlCreateButton("0 )", 245, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bl = GUICtrlCreateButton("- _", 269, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bpl = GUICtrlCreateButton("+ =", 293, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bl2 = GUICtrlCreateButton("\ |", 317, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bk = GUICtrlCreateButton("<---", 341, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$ins = GUICtrlCreateButton("Ins", 381, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$ho = GUICtrlCreateButton("Ho", 405, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$pgu = GUICtrlCreateButton("PgU", 429, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$del = GUICtrlCreateButton("Del", 381, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$end = GUICtrlCreateButton("End", 405, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$PgD = GUICtrlCreateButton("PgD", 429, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$tab = GUICtrlCreateButton("Tab", 5, 94, 33, 25)
GUICtrlSetOnEvent(-1, "type")
$Q = GUICtrlCreateButton("Q", 37, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$W = GUICtrlCreateButton("W", 61, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$E = GUICtrlCreateButton("E", 85, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$R = GUICtrlCreateButton("R", 109, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$T = GUICtrlCreateButton("T", 133, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Y = GUICtrlCreateButton("Y", 157, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$U = GUICtrlCreateButton("U", 181, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$I = GUICtrlCreateButton("I", 205, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$O = GUICtrlCreateButton("O", 229, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$p = GUICtrlCreateButton("P", 253, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bp = GUICtrlCreateButton("[ {", 277, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bp2 = GUICtrlCreateButton("] }", 301, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$enter1 = GUICtrlCreateButton("Enter", 325, 94, 41, 25)
GUICtrlSetOnEvent(-1, "type")
$caps = GUICtrlCreateButton("Caps", 5, 118, 41, 25)
GUICtrlSetOnEvent(-1, "toggle")
$A = GUICtrlCreateButton("A", 45, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$ButtonS = GUICtrlCreateButton("S", 69, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$ButtonD = GUICtrlCreateButton("D", 93, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$ButtonF = GUICtrlCreateButton("F", 117, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$G = GUICtrlCreateButton("G", 141, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$H = GUICtrlCreateButton("H", 165, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$J = GUICtrlCreateButton("J", 189, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$K = GUICtrlCreateButton("K", 213, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$L = GUICtrlCreateButton("L", 237, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bpsv = GUICtrlCreateButton("; :", 261, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bcrt = GUICtrlCreateButton("' ''", 285, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$enter = GUICtrlCreateButton("Enter", 309, 118, 57, 25)
GUICtrlSetOnEvent(-1, "type")
$Shift = GUICtrlCreateButton("Shift", 5, 142, 57, 25)
GUICtrlSetOnEvent(-1, "toggle")
$Z = GUICtrlCreateButton("Z", 61, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$X = GUICtrlCreateButton("X", 85, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$C = GUICtrlCreateButton("C", 109, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$V = GUICtrlCreateButton("V", 133, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$B = GUICtrlCreateButton("B", 157, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$n = GUICtrlCreateButton("N", 181, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$m = GUICtrlCreateButton("M", 205, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bvir = GUICtrlCreateButton(", <", 229, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bpu = GUICtrlCreateButton(". >", 253, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bpl2 = GUICtrlCreateButton("/ ?", 277, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$shift1 = GUICtrlCreateButton("Shift", 301, 142, 65, 25)
GUICtrlSetOnEvent(-1, "toggle")
$ctrl = GUICtrlCreateButton("Ctrl", 5, 166, 33, 25)
GUICtrlSetOnEvent(-1, "toggle")
$Win = GUICtrlCreateButton("Win", 37, 166, 33, 25)
GUICtrlSetOnEvent(-1, "toggle")
$Alt = GUICtrlCreateButton("Alt", 69, 166, 33, 25)
GUICtrlSetOnEvent(-1, "toggle")
$Ctrl1 = GUICtrlCreateButton("Ctrl", 333, 166, 33, 25)
GUICtrlSetOnEvent(-1, "toggle")
$win2 = GUICtrlCreateButton("Win", 301, 166, 33, 25)
GUICtrlSetOnEvent(-1, "toggle")
$alt1 = GUICtrlCreateButton("Alt", 269, 166, 33, 25)
GUICtrlSetOnEvent(-1, "toggle")
$space = GUICtrlCreateButton("Space", 101, 166, 169, 25)
GUICtrlSetOnEvent(-1, "type")
$left = GUICtrlCreateButton("<--", 381, 166, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$up = GUICtrlCreateButton("/\", 405, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$down = GUICtrlCreateButton("\/", 405, 166, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$right = GUICtrlCreateButton("-->", 429, 166, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Button21 = GUICtrlCreateButton("Num", 469, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bld = GUICtrlCreateButton("/", 493, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$bst = GUICtrlCreateButton("*", 517, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Button22 = GUICtrlCreateButton("-", 541, 70, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b77 = GUICtrlCreateButton("7", 469, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b88 = GUICtrlCreateButton("8", 493, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b99 = GUICtrlCreateButton("9", 517, 94, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Button23 = GUICtrlCreateButton("4", 469, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b55 = GUICtrlCreateButton("5", 493, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b66 = GUICtrlCreateButton("6", 517, 118, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b11 = GUICtrlCreateButton("1", 469, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b22 = GUICtrlCreateButton("2", 493, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$b33 = GUICtrlCreateButton("3", 517, 142, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Button24 = GUICtrlCreateButton("0", 469, 166, 49, 25)
GUICtrlSetOnEvent(-1, "type")
$Button25 = GUICtrlCreateButton(".", 517, 166, 25, 25)
GUICtrlSetOnEvent(-1, "type")
$Button26 = GUICtrlCreateButton("+", 541, 94, 25, 49)
GUICtrlSetOnEvent(-1, "type")
$Button27 = GUICtrlCreateButton("Ent", 541, 142, 25, 49)
GUICtrlSetOnEvent(-1, "type")

GUISetOnEvent($GUI_EVENT_CLOSE, "terminate")

GUISetState (@SW_SHOW)
WinSetOnTop($gui,"",1)

While 1
  Sleep(1000)   ; Just idle around 
WEnd


func terminate()
    Exit
EndFunc


func toggle()
    consolewrite("toggle" & @crlf)
    switch @GUI_CTRLID
        case $caps
            $shiftT = not $shiftT
        case $shift
            $shiftT = not $shiftT
        case $shift1
            $shiftT = not $shiftT
        case $ctrl
            $ctrlT = not $ctrlT
        Case $Win
            $WinT = not $WinT
        Case $Alt
            $AltT = not $AltT
        Case $Ctrl1
            $CtrlT = not $CtrlT
        Case $win2
            $winT = not $winT
        Case $alt1
            $altT = not $altT
    endswitch
EndFunc


Func type()
    switch @GUI_CTRLID
        case $A
            keysend("a")
        case $b
            keysend("b")
    endswitch
EndFunc

func keysend($chars)
    if $shiftT = 1  then $chars = "+" & $chars 
    if $ctrlT = 1  then $chars = "^" & $chars
    if $WinT = 1 or $winT = 1 then $chars = "#" & $chars
    if $AltT = 1  then $chars = "!" & $chars

    send($chars)
EndFunc
Good luck!


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites
dabus

I'd rather use a hotkey to get some window-vars...better than switching focus all the time. :)

Global $Window='', $Control=''
MsgBox(0,'Virtual Keyboard', 'Please make your selection and press <Pause>') 
HotKeySet("{PAUSE}", "GetVars")
While 1
Sleep (10)
If $Window<>'' Then Exitloop
WEnd
...
; Put your stuff here, like
ControlSend ($Window, '', $Control, 'Put your key here')

Func GetVars ()
$Window=WinGetTitle("") 
$Control=ControlGetFocus($Window)
HotKeySet("{PAUSE}", "")
EndFunc
Edited by dabus

Share this post


Link to post
Share on other sites
Kreatorul

Now works like a charm...10x so much lod3n :) Now I just have to type all the keys and done :P

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  

×