Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old October 9th, 2008, 01:37 AM
Newbie
 
Join Date: Oct 2008
Posts: 8
Default Make application buttons assign to keys up, down, left, right...

Need help to create an windows mobile application with a few buttons that when they are pressed/clicked they assign keys, like up, down, left, right.

It is just like to create a "virtual d-pad", or "software emulated d-pad".

I'm newbie in programming, and I'm using Visual Studio 2008.
Some one can help me with that?

Tanks.

My effort for it only result in this simple code lines:

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3.     Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
  4.  
  5.         'Bye!
  6.  
  7.         Application.Exit()
  8.  
  9.     End Sub
  10.  
  11.     Private Sub UpButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpButton.Click
  12.  
  13.         'Up
  14.  
  15.   *****my tries:      System.Windows.Forms.SendKeys.Send("{UP}") \\\\\\\\\ LeftButton_Click(Keys.Down, Keys.Down)     *******
  16.  
  17.     End Sub
  18.  
  19.     Private Sub LeftButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LeftButton.Click
  20.  
  21.         'Left
  22.  
  23.  
  24.  
  25.     End Sub
  26.  
  27.     Private Sub DownButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownButton.Click
  28.  
  29.         'Down
  30.  
  31.  
  32.  
  33.     End Sub
  34.  
  35.     Private Sub RightButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RightButton.Click
  36.  
  37.         'Right
  38.  
  39.  
  40.  
  41.     End Sub
  42. End Class

Last edited by insertAlias; October 31st, 2008 at 10:13 PM. Reason: added [CODE] [/CODE] tags
Reply
  #2  
Old October 9th, 2008, 10:00 AM
markmcgookin's Avatar
Moderator
 
Join Date: Dec 2006
Location: Northern Ireland / England
Age: 24
Posts: 481
Default

Hi,

Welcome to Bytes! Can I just clarify what you are after here?

So you have a device/emulator and you want 4 buttons on the screen to emulate what the "dpad" directional buttons already do? or do you simply want to create four buttons from scratch?

Either way in VS2008 this is nice and easy. Just drag four buttons onto the form, then click properties on each button, then if you already have an action on the "dpad" or softkeys as we call them you can just click the little lightning symbol at the top and find the on click event and use the drop down menu to select the same action that your soft key has... so binding the "on press" event to the same thing.

Otherwise if you just want this to be a function in it's own right, just double click on the button, and enter your code.

I'm not sure if this is what you are after, but if you have any more questions, please be a bit more specific.

Thanks,

Mark
Reply
  #3  
Old October 9th, 2008, 11:28 PM
Newbie
 
Join Date: Oct 2008
Posts: 8
Default

Quote:
Originally Posted by markmcgookin
Hi,

Welcome to Bytes! Can I just clarify what you are after here?

So you have a device/emulator and you want 4 buttons on the screen to emulate what the "dpad" directional buttons already do? or do you simply want to create four buttons from scratch?

Either way in VS2008 this is nice and easy. Just drag four buttons onto the form, then click properties on each button, then if you already have an action on the "dpad" or softkeys as we call them you can just click the little lightning symbol at the top and find the on click event and use the drop down menu to select the same action that your soft key has... so binding the "on press" event to the same thing.

Otherwise if you just want this to be a function in it's own right, just double click on the button, and enter your code.

I'm not sure if this is what you are after, but if you have any more questions, please be a bit more specific.

Thanks,

Mark


Hello.

Tanks for the answer and sorry about my english, maybe not much specific. I'm Portuguese.

I try to explain specifically what I want.

I have a Pocket PC device each don't have a dpad.

So, I'm trying to emulate/replicate the normal pocket pc dpad hardware.

I want to do one application with 4 buttons on the screen to emulate what the "dpad" directional buttons do.

I've already create those buttons with visual studio (I've placed 4 images to work as buttons. I think this is possible.)

Now, my problem is to assign functions/acctions to this buttons each makes the same as the dpad. Not getting any results. :(

If you can tell me some tips or If you can show me an example for one button, I will be tankful.

Kind regards.
Reply
  #4  
Old October 10th, 2008, 09:35 AM
markmcgookin's Avatar
Moderator
 
Join Date: Dec 2006
Location: Northern Ireland / England
Age: 24
Posts: 481
Default

Quote:
Originally Posted by ImpactMan
Hello.

Tanks for the answer and sorry about my english, maybe not much specific. I'm Portuguese.

I try to explain specifically what I want.

I have a Pocket PC device each don't have a dpad.

So, I'm trying to emulate/replicate the normal pocket pc dpad hardware.

I want to do one application with 4 buttons on the screen to emulate what the "dpad" directional buttons do.

I've already create those buttons with visual studio (I've placed 4 images to work as buttons. I think this is possible.)

Now, my problem is to assign functions/acctions to this buttons each makes the same as the dpad. Not getting any results. :(

If you can tell me some tips or If you can show me an example for one button, I will be tankful.

Kind regards.
Right, so you have dragged a .Net Picture box onto the form?

Unfortunatley I dont think there is any automatic way to replace all the functions of the soft keys, but you can code them yourself (to move inbetween items, it's selecteditemindex ++ or -- etc. Have you managed to get anything to happen when you click the image? or is that your problem? or is your problem that you have it doing things, you just can't replicate the functions of the soft keys?

To make an image clickable, you need to select it, right click > properties > click on the little lightning icon in the properties tab > then double click in the box beside "Click" and this will create an event handler (and should take you to it in the code) for the click event on the button.

Mark
Reply
  #5  
Old October 10th, 2008, 08:01 PM
Newbie
 
Join Date: Oct 2008
Posts: 8
Default

Quote:
Originally Posted by markmcgookin
Right, so you have dragged a .Net Picture box onto the form?

Unfortunatley I dont think there is any automatic way to replace all the functions of the soft keys, but you can code them yourself (to move inbetween items, it's selecteditemindex ++ or -- etc. Have you managed to get anything to happen when you click the image? or is that your problem? or is your problem that you have it doing things, you just can't replicate the functions of the soft keys?

To make an image clickable, you need to select it, right click > properties > click on the little lightning icon in the properties tab > then double click in the box beside "Click" and this will create an event handler (and should take you to it in the code) for the click event on the button.

Mark

Tanks.
I think I've already make images clickable.
But, maybe it will get me some more troubles. Do you think is better to start with simple buttons?

Doing this with simple buttons, the same way, I can't add an action to button that replicates/simulates the dpad (keys up, down....).

"Unfortunatley I dont think there is any automatic way to replace all the functions of the soft keys, but you can code them yourself (to move inbetween items, it's selecteditemindex ++ or -- etc."

I would like to try it now, but I'm on my PC with VS only Monday.
Anyway, if you can show-me some code lines example to do this, it will make me understanding the program structure and the basics for doing that.

Tanks for all your availability.

Best regardes.

Filipe



Kind regards.
Reply
  #6  
Old October 13th, 2008, 02:04 AM
Newbie
 
Join Date: Oct 2008
Posts: 8
Default

Hi!

I've been trying to make this work, but, not getting any results. :(

I don't know more what to do or how to proceed!

The only button (which is an image) that I can make work is the one to close the application. Not a progress at all!

I tink I have to see some examples do perform my program.

If you have time, and if you can, you could show me some code lines.
I will appreciate that.

Tanks.

Filipe
Reply
  #7  
Old October 16th, 2008, 05:36 AM
Newbie
 
Join Date: Oct 2008
Posts: 1
Default

I dont think there is any automatic way to replace all the functions of the soft keys, but you can code them yourself (to move inbetween items, it's selecteditemindex ++ or -- etc. Have you managed to get anything to happen when you click the image? or is that your problem? or is your problem that you have it doing things, you just can't replicate the functions of the soft keys?
Reply
  #8  
Old October 31st, 2008, 07:04 AM
Newbie
 
Join Date: Oct 2008
Posts: 5
Default

hey already explained you dude i think it will help you out
Reply
  #9  
Old October 31st, 2008, 10:29 AM
markmcgookin's Avatar
Moderator
 
Join Date: Dec 2006
Location: Northern Ireland / England
Age: 24
Posts: 481
Default

Quote:
Originally Posted by rahulsengar
Rahul Says:

You can do something like this to make it work.

Add the dll - System.runtime.IneropServices
then add this code where you initialize all the global variables
[DllImport("Coredll.dll", SetLastError = true)]
static extern int keybd_event(byte b, byte b1, int dwflags, int dwExtraInfo);

1) On menuclick1-
add this set of code when u want the display to move up
keybd_event(38, 0, 0, 0); //
keybd_event(38, 0, 2, 0); //this code Works similarly when u press up
2) On menuclick2 -
add this set of code when u want the display to move down
keybd_event(40, 0, 0, 0);
keybd_event(40, 0, 2, 0);
I have posted the above quote as it was in another thread... IMPACTMAN ... You have been warned before about this DO NOT DOUBLE POST, this is your last warning.

I will remove the other thread.

Mark
Reply
  #10  
Old October 31st, 2008, 01:32 PM
Newbie
 
Join Date: Oct 2008
Posts: 8
Default

Quote:
Originally Posted by markmcgookin
I have posted the above quote as it was in another thread... IMPACTMAN ... You have been warned before about this DO NOT DOUBLE POST, this is your last warning.

I will remove the other thread.

Mark

Hi there!

Sorry about it. I don't was't seen this post, and today I make the same mistake!! Posting again other topic with the same subject.
If you can remove it to me, I will be glad. Tanks for the info and for the help.

Regards.

Filipe
Reply
  #11  
Old October 31st, 2008, 03:49 PM
Newbie
 
Join Date: Oct 2008
Posts: 8
Default

Hello again!
I've been all morning trying to make this working.
I think now I have something "near" to working.
Can you take a look of the code and tell-me if it is ok?

Expand|Select|Wrap|Line Numbers
  1. Imports System
  2. Imports System.Runtime.InteropServices
  3.  
  4. Public Class Form1
  5.     <DllImport("coredll.dll", CallingConvention:=CallingConvention.Winapi, CharSet:=CharSet.Unicode, EntryPoint:="keybd_event", SetLastError:=True)> _
  6.     Public Shared Sub keybd_event(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)
  7.     End Sub
  8.     Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
  9.         'Bye!
  10.         Application.Exit()
  11.     End Sub
  12.  
  13.     Private Sub UpButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpButton.Click
  14.         'Up
  15.         keybd_event(26, 0, 0, 0)
  16.     End Sub
  17.  
  18.     Private Sub LeftButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LeftButton.Click
  19.         'Left
  20.         keybd_event(25, 0, 0, 0)
  21.     End Sub
  22.  
  23.     Private Sub DownButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownButton.Click
  24.         'Down
  25.         keybd_event(28, 0, 0, 0)
  26.     End Sub
  27.  
  28.     Private Sub RightButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RightButton.Click
  29.         'Right
  30.         keybd_event(27, 0, 0, 0)
  31.     End Sub
  32. End Class
Now I have other problem, that I don't know if it is possible or not to do.
Do you think is possible to make the buttons application work when one other application is running on the top of buttons application?
For example, windows explorer, or other full screen application is running and buttons application steal being able to control it, just like we have hardware buttons.
Is more alike one application that "mapping the screen" and can control all other applications like if we have hardware keys.


If some one have any tips for help, I will be tankful.

Tanks to all.

Regards.

Last edited by insertAlias; October 31st, 2008 at 10:15 PM. Reason: added [CODE] [/CODE] tags
Reply
  #12  
Old October 31st, 2008, 10:16 PM
insertAlias's Avatar
Moderator
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Age: 24
Posts: 1,936
Default

Please enclose your posted code in [CODE] [/CODE] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [CODE] [/CODE] tags in future.

MODERATOR
Reply
  #13  
Old November 1st, 2008, 06:43 AM
Newbie
 
Join Date: Oct 2008
Posts: 5
Default

hey rahul sengar says:

Actually what you did is correct
but when you are raising key board events it should have proper meaning which you not following i believe

the value for clicking the button up is 40
and the value for clicking down is 38
better you go for this

wright in google search
key code in windows mobile ( i am sure you will get the values in hexadecimal and convert it as integer type )
and set the value for a particular event
Reply
  #14  
Old November 1st, 2008, 12:34 PM
Newbie
 
Join Date: Oct 2008
Posts: 8
Default

Hello!

Tanks for the tip. I search on goolge and find Keys and Key Codes for Win Mobile and try to adapt the code to it.

Here is the changes:

Expand|Select|Wrap|Line Numbers
  1.         Private Sub UpButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpButton.Click
  2.         Const VK_UP As Byte = &H26
  3.         keybd_event(VK_UP, 0, 0, 0)
  4.         'Up
  5.     End Sub
  6.  
  7.     Private Sub LeftButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LeftButton.Click
  8.         Const VK_LEFT As Byte = &H25
  9.         keybd_event(VK_LEFT, 0, 0, 0)
  10.         'Left
  11.     End Sub 
Do you think this now will work?
For test it I need now to make the buttons application run even when any other application is running and try to control it with this "virtual buttons", but I donīt know if it's possible!?
For example, is it possible to move between items on "windows mob. file explorer" using the up and down keys of buttons application?

When I try to do it, the buttons application came to the "top" and windows file explorer control seems to be disable.

Tanks for your help.

Regards

Filipe
Reply
  #15  
Old November 3rd, 2008, 07:38 AM
markmcgookin's Avatar
Moderator
 
Join Date: Dec 2006
Location: Northern Ireland / England
Age: 24
Posts: 481
Default

You won't be able to run one on top of another like that, if you are looking to control other applications, you really need to be looking into creating a custom SIP panel with some kind of arrow keys maby.
Reply
  #16  
Old November 3rd, 2008, 10:18 AM
Newbie
 
Join Date: Oct 2008
Posts: 8
Default

Quote:
Originally Posted by markmcgookin
You won't be able to run one on top of another like that, if you are looking to control other applications, you really need to be looking into creating a custom SIP panel with some kind of arrow keys maby.
Tanks for the tip.

I will try to find something in SIP panel programing code.
I think it will be a little bit tricky...But I will try.

If you have any other tips for how to, just let me know.

Tanks
Reply
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles