XWidgetSoft Forum
https://www.bbs.xwidget.com/

ArrowKeyCommands
https://www.bbs.xwidget.com/viewtopic.php?f=8&t=3525
Page 1 of 1

Author:  Overflow [ September 14th, 2013, 6:15 am ]
Post subject:  ArrowKeyCommands

How do I make it so that if I press one of the arrow keys on my keyboard the image would change?
This is my code so far:
Code:
function widgetArrowKeyCommand1()
{
  myimage.src = "image1.png";
}
function widgetArrowKeyCommand2()
{
  myimage.src = "image2.png";
}


Instead of the "ArrowKeyCommand1/2", There's something that I need to put (for each arrow key=4keys).
Not sure what it is, hope someone can help me out here.

Thanks! :lol:

Author:  Overflow [ September 19th, 2013, 4:47 pm ]
Post subject:  Re: ArrowKeyCommands

any ideas :0?

Author:  hamid [ November 2nd, 2013, 4:05 pm ]
Post subject:  Re: ArrowKeyCommands

i'm just a user of Xwidget and sharing my experience about it:
===================
FindOut Keyboard Key Codes:

To use the keyboard keys you could use OnKeyDown Event; but it only works for Edit boxes for me when it has Typing focused to it

*Remember to use below code you should goto object edit1 and in Functions Tab set the OnKeyDown Function to edit1OnKeyDown
*and you need to create Text1 Object to see Output

Code:
function edit1OnKeyDown(Sender,Key,KeyChar,Shift)
{
  text1.Text=Key   
  //to get Charecters Key(a,b,c,...) Output use [KeyChar] after equal (text1.Text=KeyChar)
  //to get other Keys (Ctrl,alt,arrowkeys,winkey,...) Output use [Key] after equal (text1.Text=Key)
}


[text1] is name of object i create for test the Output
[KeyChar] & [Key] are variables in KeyDown Function that recieve Key Codes

===============
using Keyboard Key Codes:

after you find out the key Output you could use it this way:

Code:
function edit1OnKeyDown(Sender,Key,KeyChar,Shift)
{
  //Key Codes may be different for your keyboard so find it yourself
  if(Key=="37")  //37 is ArrowLeft //38 is ArrowUp //39 is ArrowRight //40 is ArrowDown
  {
    text1.Text="Hello World"  //Replace this line with your own Commands [myimage.src = "image1.png";]
  }
}


=========================
using Mouse Button Codes:

you could use same way for Mouse Buttons plus you could use it for all objects
for this you should set OnMouseDown Function instead of OnKeyDown Function
and in the code you should use Button instead of Key

Code:
function edit1OnMouseDown(Sender,Button,Shift,X,Y)
{
  //Key Codes may be different for your Mouse so find it yourself
  if(Key=="2")  //2 is MiddleButton //1 is RightButton //0 is LeftButton
  {
    text1.Text="Hello World"  //Replace this line with your own Commands [myimage.src = "image1.png";]
  }
}


=========================

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/