By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,319 Members | 683 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,319 IT Pros & Developers. It's quick & easy.

Make application buttons assign to keys up, down, left, right...

P: 9
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
Oct 9 '08 #1
Share this Question
Share on Google+
16 Replies

markmcgookin
Expert 100+
P: 648
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
Oct 9 '08 #2

P: 9
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.
Oct 9 '08 #3

markmcgookin
Expert 100+
P: 648
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
Oct 10 '08 #4

P: 9
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.
Oct 10 '08 #5

P: 9
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
Oct 13 '08 #6

P: n/a
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?
Oct 16 '08 #7

P: 6
hey already explained you dude i think it will help you out
Oct 31 '08 #8

markmcgookin
Expert 100+
P: 648
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
Oct 31 '08 #9

P: 9
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
Oct 31 '08 #10

P: 9
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.
Oct 31 '08 #11

Curtis Rutland
Expert 2.5K+
P: 3,256
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
Oct 31 '08 #12

P: 6
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
Nov 1 '08 #13

P: 9
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
Nov 1 '08 #14

markmcgookin
Expert 100+
P: 648
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.
Nov 3 '08 #15

P: 9
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
Nov 3 '08 #16

P: 1
Thanks for the tutorial it really helps.
Regards
Andy
<link removed>
Jun 18 '09 #17

Post your reply

Sign in to post your reply or Sign up for a free account.