Page 1 of 1 1
Topic Options
#87954 - 2002-09-16 03:34 AM Kixforms: OnKeyDown and KeyCode
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
OnKeyDown and KeyCode are the beginnings of the Kixforms keyboard interface. Two of a few methods and properties that will be making an appearance over the next few releases ...

OnKeyDown - triggered when the user depresses a key on the keyboard.

KeyCode - the keyboard code of the key that was pressed (not the ANSI char of the key that was pressed that will be implemented in another release). KeyCode is like the scan code of the key that was pressed.

For example, if one pressed ctrl-c while capturing KeyDowns and KeyCode, the result would this:

KeyCode = 17 (Ctrl)
KeyCode = 67 (The A Key)

and for shift-K it would be:

KeyCode = 16 (Shift)
KeyCode = 75 (The K Key)

So basically - it is used to capture RAW keyboard input. Heres a script that leverages this feature, it is inspired from a script written by another member of this board and submitted to me asking if this feature could be implemented.

It presents a ListBox on the left, a couple of buttons on the right, and a message and progressbar along the bottom. This script lets you select through the ListBox and choose a product to install, one may install a product by clicking the "Install" button - but the new OnKeyDown and KeyCode features allows one to select a ListBox entry and install by pressing the ENTER key.

code:
Break On

$Form = CreateObject("Kixtart.Form")
$Form.FontSize = 12
$Form.Size = 400,390

$Form.PrintXY(10,10,"Select a product and press enter:")

$ListBox = $Form.ListBox
$ListBox.Size = 200,205
$ListBox.Location = 10,50
$ListBox.FontName = Verdana
$ListBox.OnKeyDown = "ListBox_KeyDown"

For $i = 0 to 100

$ListBox.AddItem("Product #$i")

Next

$InstallButton = $Form.Button
$InstallButton.Text = "Install"
$InstallButton.Left = $ListBox.Right + 30
$InstallButton.Top = $ListBox.Top
$InstallButton.OnClick = "InstallButton_Click()"

$ExitButton = $Form.Button
$ExitButton.Text = "Exit"
$ExitButton.Left = $ListBox.Right + 30
$ExitButton.Top = $InstallButton.Bottom + 10
$ExitButton.OnClick = "ExitButton_Click()"

$Msg = $Form.Label
$Msg.Size = 370,25
$Msg.Location = 10,$ListBox.Bottom + 25
$Msg.Text = "Ready ..."

$PBar = $Form.ProgressBar
$PBar.Size = 370,25
$PBar.Location = 10,$Msg.Bottom + 5
$PBar.Min = 0
$PBar.Max = 100
$PBar.Value = 0

$Form.Center
$Form.Show
$ListBox.SetFocus
$ListBox.ListIndex = 0

While $Form.Visible
$=Execute($Form.DoEvents)
Loop

Exit 1

Function ListBox_KeyDown

If $ListBox.KeyCode = 13 ; RETURN

Install($ListBox.Value)

$ListBox.SetFocus

EndIf

EndFunction

Function InstallButton_Click()

Install($ListBox.Value)

EndFunction

Function Install($Product)

If $Product

$Msg.Text = "Installing " + $Product

For $i = 0 to $PBar.Max

$PBar.Value = $i
Sleep (0.025)

Next

$Msg.Text = "Ready ..."
$PBar.Value = 0

EndIf

EndFunction

Function ExitButton_Click()

$Form.Hide

EndFunction



[ 16. September 2002, 04:13: Message edited by: Shawn ]

Top
#87955 - 2002-09-16 04:24 AM Re: Kixforms: OnKeyDown and KeyCode
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Shawn, pressing the 'Enter' key isn't working for me. When I hit enter, the mouse cursor hide the the progress bar doesn't move. The mouse cursor reappears when I move it, but the Install() function isn't firing. It works if I hit the install button. [Frown]
Top
#87956 - 2002-09-16 04:46 AM Re: Kixforms: OnKeyDown and KeyCode
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
What os ?
Top
#87957 - 2002-09-16 05:03 AM Re: Kixforms: OnKeyDown and KeyCode
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
oh crap - i forgot - try it with Kixtart 4.12 Beta 1 ! Ruud fixed up some COM stuff that was identified ... this is one of them [Frown] guess this is a bad thing ... can't have 2.0.5 tied just to 4.12

[ 16. September 2002, 05:04: Message edited by: Shawn ]

Top
#87958 - 2002-09-17 09:50 AM Re: Kixforms: OnKeyDown and KeyCode
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Hi there Shawn,

based on the two new items I tried to fix the KiXlander script :

Added '$Form.OnKeyDown = "Form_KeyDown()"

replaced the keycheck ('IF $Form.KeyState(&26) and $fuel > 0) with another asynchronous DoEvent ('$=Execute($Form.DoEvents(1))')

and added the key checker as another function :

code:
 function Form_KeyDown()
If $Form.KeyCode = 26 and $Fuel > 0
$Speed = $Speed - 2
$Fuel = $Fuel - 5
$txtFuel.Text = $Fuel
$Thrust = 0
EndIf
endfunction

That's not working using 4.12 Beta 1

Any comments ?

J.

P.S.: It doesn't seem to even call the function [Confused]
hmmm ... maybe it does work only with listboxes actually ?

[ 17. September 2002, 10:40: Message edited by: jpols ]
_________________________



Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 557 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.053 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org