KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Keyboard navigation within a form

 
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic
View previous topic :: View next topic  
Author Message
pdac
KiXforms Novice
KiXforms Novice


Joined: 23 Oct 2008
Posts: 3

PostPosted: Thu Oct 23, 2008 12:49 pm    Post subject: Keyboard navigation within a form Reply with quote

I've just picked up KixFoms 2.46.55.0 and thought I would experiment with something I've been trying to find a way of doing for years.

The following VB script is my first stab at creating a generic checkbox-based selection dialog. My problem is that it seems to work fine with mouse input, but I cannot get any keyboard navigation to work. I want to be able to do the following:

1. Move between the selections with the arrow keys
2. Move around with the TAB key
3. Use the ENTER key as an alternative to clicking the OK button.
4. Use the SPACE key to select the control with focus

Can anyone offer any advice as to how I might do these things?

Pete
========================================
Here's the script:

Code:
Function GetChoice(Title, Text, Buttons)
    Const Margin=10, CharWidth=8, LineHeight=24, ExtraWidth=10, ExtraHeight=80
    Dim ButtonArray, Button, MaxLen, YPos, ControlWidth, GetChoiceBusy, GetChoiceResult

    GetChoice = -1
    If (VarType(Buttons) And vbArray) Then
        ButtonArray = Buttons
    Else
        ButtonArray = Split(Buttons, ";")
    End If
    MaxLen = Len(Text)
    For Button = LBound(ButtonArray) To UBound(ButtonArray)
        ButtonArray(Button) = Split(ButtonArray(Button), "=")
        If Len(ButtonArray(Button)(1)) > MaxLen Then
            MaxLen = Len(ButtonArray(Button)(1))
        End If
    Next
    With CreateObject("kixtart.system")
        With .Form()
            .Text = Title
            .Width = Margin + Margin + ExtraWidth + (CharWidth * MaxLen)
            .Height = Margin + Margin + ExtraHeight + (LineHeight * (UBound(ButtonArray)+1))
            .FontName = "Courier"
            .FontSize = 10
            .onClick = ""
            YPos = Margin
            ControlWidth = .Width - Margin - Margin
            With .Controls.Add("Label")
                .Left = Margin
                .Top = YPos
                .Width = ControlWidth
                .Height = LineHeight - 4
                .Text = Text
            End With
            For Button = LBound(ButtonArray) To UBound(ButtonArray)
                YPos = YPos + LineHeight
                With .Controls.Add("RadioButton")
                    .Left = Margin
                    .Top = YPos
                    .Width = ControlWidth
                    .Height = LineHeight - 4
                    .Text = ButtonArray(Button)(1)
                    If Left(ButtonArray(Button)(0),1) = "+" Then
                        .Checked = True
                        GetChoiceResult = Mid(ButtonArray(Button)(0), 2)
                        .onClick = "GetChoiceResult = " & GetChoiceResult
                    Else
                        .onClick = "GetChoiceResult = " & ButtonArray(Button)(0)
                    End If
                End With
            Next
            With .Controls.Add("Button")
                .Top = YPos + LineHeight
                .Width = CharWidth * 12
                .Left = Margin + ControlWidth - .Width - 10
                .Height = LineHeight
                .Text = "OK"
                .onClick = "GetChoiceBusy = False"
            End With
            GetChoiceBusy = True
            .Show()
            Do
                WScript.Sleep(100)
                Execute(.DoEvents(True))
            Loop Until GetChoiceBusy = False
            GetChoice = GetChoiceResult
        End With
    End With
End Function

Result = GetChoice("Choice", "Select one of the following:", "+1=Red")
MsgBox("Result=" & Result)
Result = GetChoice("Choice", "Select one of the following:", "+1=&Red;2=&Orange;3=&Yellow;4=&Green;5=&Blue;6=&Indigo;7=&Violet")
MsgBox("Result=" & Result)
Result = GetChoice("Choice", "Select one of the following:", Split("1=Red@+2=Orange@3=Yellow","@"))
MsgBox("Result=" & Result)
Back to top
View user's profile Send private message
pdac
KiXforms Novice
KiXforms Novice


Joined: 23 Oct 2008
Posts: 3

PostPosted: Thu Oct 23, 2008 12:51 pm    Post subject: Reply with quote

Hmm. Not sure where the indentation went to there. Maybe someone can let me know how to post code samples to this forum.
Back to top
View user's profile Send private message
pearly
KiXforms Aficionado
KiXforms Aficionado


Joined: 27 Jan 2004
Posts: 332

PostPosted: Thu Oct 23, 2008 5:47 pm    Post subject: Reply with quote

You'll need to use the code tags

code /code (in brackets)
Back to top
View user's profile Send private message
Gargoyle
KiXforms Aficionado
KiXforms Aficionado


Joined: 30 Dec 2003
Posts: 366
Location: Arizona

PostPosted: Thu Oct 23, 2008 7:28 pm    Post subject: Reply with quote

You will want to utilize the KeyDown event handler. Then you can write a function to check the KeyCode and make a decision based upon what KeyCode you recieve.
_________________
Parents were invented to make children happy by giving them something to ignore.
Back to top
View user's profile Send private message
pdac
KiXforms Novice
KiXforms Novice


Joined: 23 Oct 2008
Posts: 3

PostPosted: Fri Oct 24, 2008 9:17 pm    Post subject: Reply with quote

Thanks for the advice on the key-down event - I'll look into this.

Also thatnks for the advice on the 'code' tag - I'll look into this one too.
Back to top
View user's profile Send private message
Rod
KiXforms Webmaster
KiXforms Webmaster


Joined: 22 Feb 2003
Posts: 202
Location: United Kingdom

PostPosted: Sat Oct 25, 2008 2:23 pm    Post subject: Reply with quote

I edited your original post so that the code now displays correctly. Incidentally, please ensure that you do not have the "Disable BBCode in this post" option checked otherwise the tags will have no effect.

Rod.

_________________
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Lonkero
KiXforms Devotee
KiXforms Devotee


Joined: 13 Mar 2003
Posts: 1022
Location: Espoo, Finland

PostPosted: Sun Oct 26, 2008 10:33 am    Post subject: Reply with quote

for the enter press, see default property in the manual.
_________________
Hammer
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group