Jump to content
Sign in to follow this  
myspacee

Draw 3x3 grid on desktop

Recommended Posts

myspacee

hello to all,

try to assemble different idea to build a script.

(mouse gesture writing method)

Need info about draw lines and squares on desktop.

My final goal is draw a 3x3 grid and obtain position info

when mouse enter in one of these grid.

thank you for any info,

m.

Share this post


Link to post
Share on other sites
myspacee

nice reading but can't find nothing usefull for my idea.

Try again to formulate question :

is possible to build a 3x3 grid and obtain info\value when mouse hover on a cell ?

m.

Edited by myspacee

Share this post


Link to post
Share on other sites
FaT3oYCG

why do you want to do that and what info do you need to obtain?


Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Share this post


Link to post
Share on other sites
Andreik

I think that an example helps you:

HotKeySet("{ESC}","Quit")

Global $handle = DLLCall("user32.dll","long","GetDC","hwnd",0)

Func PixelDraw($XCoord, $YCoord, $Color)
   DllCall("gdi32","long","SetPixel", "long",$handle[0], "long", $XCoord, "long", $YCoord, "long", $Color)
   If @error = 1 Then
      Return 0
   Else
      Return 1
   EndIf
EndFunc

$X = @DesktopWidth
$Y = @DesktopHeight

For $C1 = 0 To $X
    For $C2 = Int($Y/3) To $Y Step Int($Y/3)
        PixelDraw($C1,$C2,0xCC00CC)
    Next
Next

For $C1 = Int($X/3) To $X Step Int($X/3)+1
    For $C2 = 0 To $Y
        PixelDraw($C1,$C2,0xCC00CC)
    Next
Next

While 1
    $POS = MouseGetPos()
    If ($POS[0] < Int($X/3) And $POS[1] < Int($Y/3)) Then TrayTip("SQUARE","#1",1)
    If ($POS[0] < Int($X/3) And ($POS[1] > Int($Y/3) And $POS[1] < 2*Int($Y/3))) Then TrayTip("SQUARE","#4",1)
    If ($POS[0] < Int($X/3) And $POS[1] > 2*Int($Y/3)) Then TrayTip("SQUARE","#7",1)
    If (($POS[0] > Int($X/3) And $POS[0] < 2*Int($X/3)) And $POS[1] < Int($Y/3)) Then TrayTip("SQUARE","#2",1)
    If (($POS[0] > Int($X/3) And $POS[0] < 2*Int($X/3)) And ($POS[1] > Int($Y/3) And $POS[1] < 2*Int($Y/3))) Then TrayTip("SQUARE","#5",1)
    If (($POS[0] > Int($X/3) And $POS[0] < 2*Int($X/3)) And $POS[1] > 2*Int($Y/3)) Then TrayTip("SQUARE","#8",1)
    If ($POS[0] > 2*Int($X/3) And $POS[1] < Int($Y/3)) Then TrayTip("SQUARE","#3",1)
    If ($POS[0] > 2*Int($X/3) And ($POS[1] > Int($Y/3) And $POS[1] < 2*Int($Y/3))) Then TrayTip("SQUARE","#6",1)
    If ($POS[0] > 2*Int($X/3) And $POS[1] > 2*Int($Y/3)) Then TrayTip("SQUARE","#9",1)
    Sleep(50)
WEnd

Func Quit()
    Exit
EndFunc
Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites
Malkey

hello to all,

try to assemble different idea to build a script.

(mouse gesture writing method)

Need info about draw lines and squares on desktop.

My final goal is draw a 3x3 grid and obtain position info

when mouse enter in one of these grid.

thank you for any info,

m.

From the specifications you stipulated, I imagined a small 3x3 grid.

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

Opt('MustDeclareVars', 1)

Global $GuiW = 120, $GuiH = 120

Example()

Func Example()
    Local $msg, $hGui, $aMPos, $XSquare, $YSquare, $aWinPos
    $hGui = GUICreate("My Main", $GuiW, $GuiH, -1, -1, $WS_POPUPWINDOW, $WS_EX_TOPMOST)
    WinSetTrans("My Main", "", 40)
    GUICtrlCreateGraphic(0, 0, $GuiW, $GuiH)
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $GuiH / 3)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, $GuiW, $GuiH / 3)
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $GuiH * 2 / 3)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, $GuiW, $GuiH * 2 / 3)
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $GuiW / 3, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, $GuiW / 3, $GuiH)
    GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $GuiW * 2 / 3, 0)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff)
    GUICtrlSetGraphic(-1, $GUI_GR_LINE, $GuiW * 2 / 3, $GuiH)
    GUISetState()
    Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client
    
    Do
        Local $sWinRect = _WinAPI_GetWindowRect(WinGetHandle("My Main"))
        Local $MP = _WinAPI_GetMousePos()
        If _WinAPI_PtInRect($sWinRect, $MP) Then
            $aMPos = MouseGetPos()
            $XSquare = Int($aMPos[0] / ($GuiW / 3)) + 1  ; ($GuiW / 3) = Width of each square
            $YSquare = Int($aMPos[1] / ($GuiH / 3))      ; ($GuiH / 3) = Height of each square
            $aWinPos = WinGetPos("My Main")
            ToolTip("Square Number: " & $XSquare + $YSquare * 3, $aMPos[0] + $aWinPos[0] + 15, $aMPos[1] + $aWinPos[1] + 5)
        EndIf
        $msg = GUIGetMsg()
        Sleep(10)
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Share this post


Link to post
Share on other sites
myspacee

thank you all for replies,

i'm collecting info about T9 - mouse gesture - virtual keyboard/input

I, and lot of fried, have a problem.

A PC connected with living room TV as mediacenter and same problem to input text on it.

Is very difficult to find good keyboard for this ambient (co$t a lot, ugly to see, wife, etc)

so we 'invent' a new way to write using only mouse. but we need skill to write a program

for this idea.

post image in hope to explain method:

Posted Image

based on dictionary, we simulate input based on T9 (mobiles) engine.

every movement = number = letter

not find neither T9 emulation input for remote, that we considere a nice sobstitution,

joined wtih word premonition can be a solution to our problem.

My english maybe is not so good to explain concept, but image can help to understand,

Anyone want to help, not only me, but several HTPC user ?

Thank you all for your time,

m.

PS: forgot to say thank you to Andreik and Malkey

Malkey, very elegant grid, can you teach me how add label to squares ?

Edited by myspacee

Share this post


Link to post
Share on other sites
myspacee

yes, but there is a peculiarity. Keyboard is not fixed on screen.

_________ Step 1

When you select a letter from floating T9 keyboard, keyboard disappear,

and re-initialize under mouse. So you can compose word with gesture on desktop,

following keyboard ways.

Hope that now posted image is more clear to understand.

_________ Step 2

Final goal is click on few 'letter', engine can search all corresponding 'number' in dictionary,

and suggest its T9 possible 'words'.

Follow my T9 based dictionary idea:

23;be
26;an
26;am
27;as
28;at
29;by
36;do
43;he
43;if
46;in
46;go
47;is
48;it
63;of

suppose i would word 'go'.

click on number 4 (label 'ghi'), and program list me only 4 starting words:

43;he
43;if
46;in
46;go
47;is
48;it

hope you can understand all my confused explanations,

m.

Share this post


Link to post
Share on other sites
myspacee

For now i'm focused on first step (floating T9 keyboard)

You would need to read the file into an array and read on each click.

Maybe not, T9 dictionary can help in this task.

you can :

- read all words starting with first number and put in array

- delete all words that don't have second letter =

- delete all words that don't have third letter =

- and go on...

or star research/suggestion from second inserted letter, different approach can be applied...

Post some code from search text on file :

(thank you again GEOSoft)

$sFile = @ScriptDir & "\Test.txt"

GUICreate("Test GUI", 170, 210)
$in = GUICtrlCreateInput("", 10, 10, 150, 20)
$Edit = GUICtrlCreateEdit("", 10, 40, 150, 160)
GUISetState()
While 1
    $sIn = GUICtrlRead($in)
    If StringLen($sIn) >= 1 Then
        $sOut = ""
        $aRegEx = StringRegExp(FileRead($sFile), "(?i)(?m)^(" & $sIn & ".*)$", 3)
        If IsArray($aRegEx) Then
            For $i = 0 To Ubound($aRegEx) - 1
                $sOut &= $aRegEx[$i] & @CRLF
            Next
            If GUICtrlRead($Edit) <> StringStripWS($sOut, 2) Then GUICtrlSetData($Edit, StringStripWS($sOut, 2))
        Else
            If GUICtrlRead($Edit) <> "" Then GUICtrlSetData($Edit, "")
        EndIf
    Else
        If GUICtrlRead($Edit) <> "" Then GUICtrlSetData($Edit, "")
    EndIf
    If GUIGetMsg() = -3 Then ExitLoop
Wend

m.

Edited by myspacee

Share this post


Link to post
Share on other sites
myspacee

attach T9 dictionary for top 1000 english words that i want do use with this tool

With excel you can isolate words with = T9 code, very very few.

m.

Edited by myspacee

Share this post


Link to post
Share on other sites
myspacee

hard to explain i search to put togheter code for a working example.

Can anyone help me to put 'label' on Malkey grid script ?

thank you,

m.

Share this post


Link to post
Share on other sites
James

I have a set of buttons. At the moment the buttons are generated in a grid.

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

;Opt('MustDeclareVars', 1)
Opt("MouseCoordMode", 2);1=absolute, 0=relative, 2=client

Global $GuiW = 120, $GuiH = 120
Global $msg, $hGui, $aMPos, $XSquare, $YSquare, $aWinPos
Global $sWinRect = _WinAPI_GetWindowRect(WinGetHandle("My Main"))
Global $MP = _WinAPI_GetMousePos()
Global $Dict = @ScriptDir & '\T9Dict.dic', $hString, $in, $out
Dim $gridWidth = 3, $gridHeight = 3
Dim $btnArray[$GuiH][$GuiW][3]

$hGui = GUICreate("My Main", $GuiW, $GuiH, -1, -1, $WS_POPUPWINDOW, $WS_EX_TOPMOST)
;WinSetTrans("My Main", "", 40)

; Buttons
; Buttons
$num = 1
For $Y = 0 To $gridHeight - 1
    For $X = 0 To $gridWidth - 1
        $btnArray[$Y][$X][0] = GUICtrlCreateButton($num, ($X * 40), ($Y * 40), 40, 40)
       ;GUICtrlSetOnEvent(-1, "buttonPress")
        GUICtrlSetFont (-1,9, default)
       
        $btnArray[$Y][$X][1] = false
       
        $btnArray[$Y][$X][2] = $num
        $num += 1
    Next
Next

GUICtrlCreateGraphic(0, 0, $GuiW, $GuiH)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $GuiH / 3)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $GuiW, $GuiH / 3)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, $GuiH * 2 / 3)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $GuiW, $GuiH * 2 / 3)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $GuiW / 3, 0)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $GuiW / 3, $GuiH)
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $GuiW * 2 / 3, 0)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $GuiW * 2 / 3, $GuiH)
GUISetState()

While 1
    If _WinAPI_PtInRect($sWinRect, $MP) Then
        $aMPos = MouseGetPos()
        $XSquare = Int($aMPos[0] / ($GuiW / 3)) + 1; ($GuiW / 3) = Width of each square
        $YSquare = Int($aMPos[1] / ($GuiH / 3)); ($GuiH / 3) = Height of each square
        $aWinPos = WinGetPos("My Main")
        ToolTip("Square Number: " & $XSquare + $YSquare * 3, $aMPos[0] + $aWinPos[0] + 15, $aMPos[1] + $aWinPos[1] + 5)
    EndIf
    
    $iMsg = GUIGetMsg()
    
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

I am half way through making it read the dictionary etc. There is probably an easier way to do this :mellow:

Share this post


Link to post
Share on other sites
myspacee

your script is surely on right way.

3 thing miss to follow my intentions:

- label (to recognise which letter I push) (2=abc 3=def 4=ghi etc) (if grid is trasparent can we attach image with SplashImageOn?)

- when i push on a square its value go in a variable ($my_sequence = $my_sequence & $last_button_pressed)

- when i push on button exe redraw grid under mouse to let me choose next number

JamesBrooks thank you very much for your time,

m.

Share this post


Link to post
Share on other sites
James

Yes I know they are missing but thank you for confirming!

Is using buttons a good idea? We could make clickable labels if that is for sure what you need. I have not yet added the ability to click buttons but a current version I am working on is nearing that status.

Edit:

Thought I'd mention at before I went to sleep I started editing the script you posted from George to work with what I have. Also, how would you like to press space? Surely you will need the *0 and hash (sorry the Mac doesn't have a hash key). Star to change through the word, 0 for a space and hash to change capitalization?

Edited by JamesBrooks

Share this post


Link to post
Share on other sites
James

Newer version. This time the GUI is situated in the lower right of the screen above the task bar. Still can't figure out how to read the T9 like this.

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

Opt("GUIOnEventMode", 1); Change to OnEvent mode
Opt("MouseCoordMode", 2);1=absolute, 0=relative, 2=client

Global $GuiW = 120, $GuiH = 120
Global $msg, $hGui, $aMPos, $XSquare, $YSquare, $aWinPos
Global $sWinRect = _WinAPI_GetWindowRect(WinGetHandle("My Main")), $MP = _WinAPI_GetMousePos()
Global $Dict = @ScriptDir & '\T9Dict.dic', $hString, $in, $out
Global $aCPos = ControlGetPos("[CLASS:Shell_TrayWnd]", "", ""); Taskbar
Global $Width = @DesktopWidth, $Height = @DesktopHeight
Dim $gridWidth = 3, $gridHeight = 3, $btnArray[$GuiH][$GuiW]

; Get the desktop size without the taskbar
If $aCPos[3] > $aCPos[2] Then
    $Width = @DesktopWidth - $aCPos[2]
Else
    $Height = @DesktopHeight - $aCPos[3]
EndIf

; Create the GUI
$hGui = GUICreate("My Main", $GuiW, $GuiH, $Width - $GuiW, $Height - $GuiW, $WS_POPUPWINDOW, $WS_EX_TOPMOST)
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
;WinSetTrans("My Main", "", 40)

; Buttons
$num = 1
For $Y = 0 To $gridHeight - 1
    For $X = 0 To $gridWidth - 1
        $btnArray[$Y][$X] = GUICtrlCreateButton($num, ($X * 40), ($Y * 40), 40, 40)
        GUICtrlSetOnEvent(-1, "buttonPress")
        $num += 1
    Next
Next

GUISetState()

Do
    $msg = GUIGetMsg()
    Sleep(10)
Until $msg = $GUI_EVENT_CLOSE

Func buttonPress()
    Local $aString, $sOut = "", $Edit = ""
    For $Y = 0 To $gridHeight - 1
        For $X = 0 To $gridWidth - 1
            If @GUI_CtrlId = $btnArray[$Y][$X] Then
                MsgBox(0, "Grid Ref", $X & "," & $Y)
            EndIf
        Next
    Next
EndFunc  ;==>buttonPress

Func Close()
    Exit
EndFunc  ;==>Close

I have removed the grid and the tooltip as this is not needed if the buttons stay.

Share this post


Link to post
Share on other sites
myspacee

ok now i'm using button, so ugly but no choise for me (bad bad coder)

working T9 engine:

#include <GUIConstants.au3>

dim $user_insert, $num

$sFile = @ScriptDir & "\T9_dict_top1000_ENG.txt"

;////////////////// GUI ///////////////////////
$Form1 = GUICreate("T9 FOR PC", 334, 454, 420, 265)
$OK = GUICtrlCreateButton("OK", 0, -1, 50, 50, 0)
$ABC = GUICtrlCreateButton("ABC", 49, 0, 50, 50, 0)
$DEF = GUICtrlCreateButton("DEF", 97, 0, 50, 50, 0)
$GHI = GUICtrlCreateButton("GHI", 0, 48, 50, 50, 0)
$JKL = GUICtrlCreateButton("JKL", 49, 48, 50, 50, 0)
$MNO = GUICtrlCreateButton("MNO", 97, 47, 50, 50, 0)
$PQRS = GUICtrlCreateButton("PQRS", 0, 98, 50, 50, 0)
$TUV = GUICtrlCreateButton("TUV", 49, 98, 50, 50, 0)
$WXYZ = GUICtrlCreateButton("WXYZ", 97, 98, 50, 50, 0)
$in = GUICtrlCreateInput("", 162, 10, 150, 21)
$Edit = GUICtrlCreateEdit("", 162, 36, 150, 392)
GUICtrlSetData(-1, "")
GUISetState(@SW_SHOW)
;////////////////// GUI ///////////////////////



While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ABC
            button_input(2)

        Case $DEF
            button_input(3)

        Case $GHI
            button_input(4)

        Case $JKL
            button_input(5)
        
        Case $MNO
            button_input(6)

        Case $PQRS
            button_input(7)

        Case $TUV
            button_input(8)

        Case $WXYZ
            button_input(9)
            
        Case $OK
            $user_insert = ""
            GUICtrlSetData($in, '')

    EndSwitch
        
        
Wend
    
    
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;          functions   
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Func button_input($num)
    
    GUICtrlSetData($in, '')
    
    $user_insert = $user_insert & $num 
    
;~   If $user_insert = 'get' Then
;~       get()
;~   Else
        
        If $num = 'nul' Then
            GUICtrlSetData($in, GUICtrlRead($in) & 0)
        Else
            GUICtrlSetData($in, GUICtrlRead($in) & $user_insert)
        EndIf

;~   EndIf

    search_word()
EndFunc  
    
    
Func search_word()
    $sIn = GUICtrlRead($in)
    
    If StringLen($sIn) >= 1 Then
        $sOut = ""
        $aRegEx = StringRegExp(FileRead($sFile), "(?i)(?m)^(" & $sIn & ".*)$", 3)
        If IsArray($aRegEx) Then
            For $i = 0 To Ubound($aRegEx) - 1
                $sOut &= $aRegEx[$i] & @CRLF
            Next
            If GUICtrlRead($Edit) <> StringStripWS($sOut, 2) Then GUICtrlSetData($Edit, StringStripWS($sOut, 2))
        Else
            If GUICtrlRead($Edit) <> "" Then GUICtrlSetData($Edit, "")
        EndIf
    Else
        If GUICtrlRead($Edit) <> "" Then GUICtrlSetData($Edit, "")
    EndIf
        
;~   If GUIGetMsg() = -3 Then ExitLoop
    
EndFunc

dream is floating and trasparent keyboard (maybe an image),

your first code is pefect for this because it knows where mouse is,

but with buttons is hard to do (for me)

give a try,

m.

Share this post


Link to post
Share on other sites
James

Hmm I could steal your code. Buttons are not that hard when you understand them. They way I have done it is by generating a grid of 3x3. Then they are given a numerical value. By storing each button in an array we can easily control what happens to them.

My current problem is storing the list of available words not in an edit control but a variable. I know it sounds stupid and I am probably being a right dick by missing this.

By the way, what do you think of what I have so far?

Edited by JamesBrooks

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.