Jump to content
Sign in to follow this  
bladem2003

navigate with the arrow keys

Recommended Posts

hello,

i want to create a virtual keyboard in that i can navigate with the arow keys. How can i navigate up and down? 

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

AutoItSetOption("GUIResizeMode", $GUI_DOCKAUTO)

Global $aButtons[47]

Global $aKeys[47] = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", _
        "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", ",", ".", "/", "Enter"]



$hGUI = GUICreate("VK", 300, 125, 500, 100, BitOR($WS_SYSMENU, $WS_POPUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_NOACTIVATE))

$iCount = 0
For $j = 0 To 3
    For $i = 0 To 11
        If $j = 3 and $i = 10 Then
            $aButtons[$iCount] = GUICtrlCreateButton("", $i * 25, $j * 25, 50, 25)
        Else
            $aButtons[$iCount] = GUICtrlCreateButton("", $i * 25, $j * 25, 25, 25)
        EndIf
        GUICtrlSetData(-1, $aKeys[$iCount])
        $iCount += 1
        GUICtrlSetFont(-1, 10)
        If $iCount > 46 Then ExitLoop
    Next
Next

GUISetState()

$swX = 800
$swY = 230
WinMove($hGUI, "", (@DesktopWidth - $swX) / 2, @DesktopHeight - $swY, $swX, $swY);488)

$iCount = 0
For $j = 0 To 3
    For $i = 0 To 11
        GUICtrlSetFont($aButtons[$iCount], (20 / 240) * ($swY), 80, 1, "ARIAL")
        $iCount += 1
        If $iCount > 46 Then ExitLoop
    Next
Next



While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd

 

osk.jpg

Share this post


Link to post
Share on other sites

Very hard coded but you will get the idea :

#include <Constants.au3>
#include <GUIConstants.au3>
#include <WinAPISysWin.au3>

AutoItSetOption("GUIResizeMode", $GUI_DOCKAUTO)

Global $aButtons[47]

Global $aKeys[47] = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", _
        "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", ",", ".", "/", "Enter"]

$hGUI = GUICreate("VK", 300, 125, 500, 100, BitOR($WS_SYSMENU, $WS_POPUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_NOACTIVATE))

HotKeySet ("{UP}", "_up")
HotKeySet ("{ESC}", "_exit")
HotKeySet ("{DOWN}", "_down")

$iCount = 0
For $j = 0 To 3
    For $i = 0 To 11
        If $j = 3 and $i = 10 Then
            $aButtons[$iCount] = GUICtrlCreateButton("", $i * 25, $j * 25, 50, 25)
        Else
            $aButtons[$iCount] = GUICtrlCreateButton("", $i * 25, $j * 25, 25, 25)
        EndIf
        GUICtrlSetData(-1, $aKeys[$iCount])
        $iCount += 1
        GUICtrlSetFont(-1, 10)
        If $iCount > 46 Then ExitLoop
    Next
Next

GUISetState()

$swX = 800
$swY = 230
WinMove($hGUI, "", (@DesktopWidth - $swX) / 2, @DesktopHeight - $swY, $swX, $swY);488)

$iCount = 0
For $j = 0 To 3
    For $i = 0 To 11
        GUICtrlSetFont($aButtons[$iCount], (20 / 240) * ($swY), 80, 1, "ARIAL")
        $iCount += 1
        If $iCount > 46 Then ExitLoop
    Next
Next

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then _exit ()
WEnd

Func _up ()
  Local $pos = GetPosition ()
  if $pos = -1 then Return
  if $pos > 11 then Send ("{LEFT 12}")
EndFunc

Func _down ()
  Local $pos = GetPosition ()
  if $pos = -1 then Return
  if $pos < 34 then Send ("{RIGHT  12}")
  if $pos = 35 then Send ("{RIGHT  11}")
EndFunc

Func GetPosition ()
Local $hndl = _WinAPI_GetFocus (), $button = -1

  For $i = 0 to Ubound($aButtons)-1
    if $hndl = GUICtrlGetHandle ($aButtons[$i]) Then
      $button = $i
      ExitLoop
    EndIf
  Next

  Return $button

EndFunc

Func _exit ()
  Exit
EndFunc

 

Share this post


Link to post
Share on other sites

thank you so much.
I solved it in that way

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <array.au3>

HotKeySet("{RIGHT}", "_rightOsk")
HotKeySet("{LEFT}", "_leftOsk")
HotKeySet("{DOWN}", "_downOsk")
HotKeySet("{UP}", "_upOsk")
HotKeySet("{ENTER}", "_enterOsk")

AutoItSetOption("GUIResizeMode", $GUI_DOCKAUTO)

Global $aButtons[5][47], $iPosX, $iPosY

Global $aKeys2[5][14] = [["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "="], _
        ["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", ",", ".", "/", "Enter"], _
        ["space", "back"]]
;_ArrayDisplay($aKeys2)

$hGUI = GUICreate("VK", 300, 125, 500, 100, BitOR($WS_SYSMENU, $WS_POPUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_NOACTIVATE))


For $j = 0 To 3
    $iCount = 0
    For $i = 0 To 11
        If $j = 3 And $i = 10 Then
            $aButtons[$j][$iCount] = GUICtrlCreateButton("", $i * 25, $j * 25, 50, 25)
            GUICtrlSetData(-1, $aKeys2[$j][$iCount])
            GUICtrlSetFont(-1, 10)
            ExitLoop
        Else
            $aButtons[$j][$iCount] = GUICtrlCreateButton("", $i * 25, $j * 25, 25, 25)
            GUICtrlSetData(-1, $aKeys2[$j][$iCount])
            GUICtrlSetFont(-1, 10)
        EndIf
        $iCount += 1
    Next
Next


$i = 3
$aButtons[4][0] = GUICtrlCreateButton("", $i * 25, $j * 25, 150, 25, $WS_GROUP)
GUICtrlSetData(-1, "Space")
GUICtrlSetFont(-1, 10)

$i = 9
$drag = GUICtrlCreateLabel("", $i * 25.2, $j * 25.4, 29, 24, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, 0x6E7B8B)

$i = 10
$aButtons[4][1] = GUICtrlCreateButton("", $i * 25.5, $j * 25, 45, 25, $WS_GROUP)
GUICtrlSetData(-1, "<--")
GUICtrlSetFont(-1, 10)

GUISetState()

$swX = 800
$swY = 230
WinMove($hGUI, "", (@DesktopWidth - $swX) / 2, @DesktopHeight - $swY, $swX, $swY);488)

For $j = 0 To 4
    For $i = 0 To 11
        GUICtrlSetFont($aButtons[$j][$i], (20 / 240) * ($swY), 80, 1, "ARIAL")
    Next
Next

$iPosY = 0
$iPosX = 0
GUICtrlSetBkColor($aButtons[$iPosY][$iPosX], 0xff0000)

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
WEnd


Func _rightOsk()
    If $aKeys2[$iPosY][$iPosX + 1] <> "" Then
        GUICtrlSetBkColor($aButtons[$iPosY][$iPosX], 0xffffff)
        $iPosX += 1
        GUICtrlSetBkColor($aButtons[$iPosY][$iPosX], 0xff0000)
    EndIf
EndFunc   ;==>_rightOsk

Func _leftOsk()
    If $iPosX - 1 <> -1 Then
        GUICtrlSetBkColor($aButtons[$iPosY][$iPosX], 0xffffff)
        $iPosX -= 1
        GUICtrlSetBkColor($aButtons[$iPosY][$iPosX], 0xff0000)
    EndIf
EndFunc   ;==>_leftOsk

Func _downOsk()
    If $iPosY + 1 <> 5 Then
        GUICtrlSetBkColor($aButtons[$iPosY][$iPosX], 0xffffff)
        If $iPosY = 2 And $iPosX = 11 Then
            $iPosY += 1
            $iPosX -= 1
            GUICtrlSetBkColor($aButtons[$iPosY][$iPosX], 0xff0000)
        ElseIf $iPosY = 3 Then ;And $iPosX = 5 Then
            $iPosY += 1
            If $iPosX < 9 Then $iPosX = 0
            If $iPosX > 8 Then $iPosX = 1
            GUICtrlSetBkColor($aButtons[$iPosY][$iPosX], 0xff0000)
        Else
            $iPosY += 1
            GUICtrlSetBkColor($aButtons[$iPosY][$iPosX], 0xff0000)

        EndIf
    EndIf
EndFunc   ;==>_downOsk


Func _upOsk()
    If $iPosY - 1 <> -1 Then
        GUICtrlSetBkColor($aButtons[$iPosY][$iPosX], 0xffffff)
        If $iPosY = 4 Then $iPosX = 5
        $iPosY -= 1
        GUICtrlSetBkColor($aButtons[$iPosY][$iPosX], 0xff0000)
    EndIf
EndFunc   ;==>_upOsk

Func _enterOsk()
    ConsoleWrite($aKeys2[$iPosY][$iPosX] & @CRLF)
EndFunc   ;==>_enterOsk

 

Edited by bladem2003

Share this post


Link to post
Share on other sites
7 hours ago, bladem2003 said:

I solved it in that way

Nice. Only problem with your approach is that you cannot use mouse to select a key...

Look also for GUI accelerator keys instead of HotKeySet.  I didn't bother with it, but that's something may interest you.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...