473,395 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

String to Byte? Convert.ToByte(textbox1.text)

Hey guys I have written a small application that will send keys from the
keyboard depending on the users input. My thing is I can't use SendKeys.Send
because i need to emulate the keyboard pressing the keys so I am using
Keybd_Event from user32.dll.

When the user gives their input they place the number they would like to
send into textbox1. I need to some how be able to convert the 0 - 9 to be
0x30 - 0x39. I was thinking I could just use: keybd_event(0x30 +
Convert.ToByte(textBox1.Text), 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0); but
that doesn't work. I'm in a rut because I have been spending to much time on
this last detail. Any help would be great! Thank you so much!!!
Mar 7 '06 #1
4 6398
Chris,

Why not create a map where the 0-9 will correspond to the appropriate
VK_ constants? Then, you just perform the lookup, and send that virtual key
code.

Also, you should not be using keybd_event on W2K and XP systems. You
should be using SendInput instead.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chris242" <Ch******@discussions.microsoft.com> wrote in message
news:44**********************************@microsof t.com...
Hey guys I have written a small application that will send keys from the
keyboard depending on the users input. My thing is I can't use
SendKeys.Send
because i need to emulate the keyboard pressing the keys so I am using
Keybd_Event from user32.dll.

When the user gives their input they place the number they would like to
send into textbox1. I need to some how be able to convert the 0 - 9 to be
0x30 - 0x39. I was thinking I could just use: keybd_event(0x30 +
Convert.ToByte(textBox1.Text), 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
but
that doesn't work. I'm in a rut because I have been spending to much time
on
this last detail. Any help would be great! Thank you so much!!!

Mar 7 '06 #2

Nicholas,

Sorry for such a silly question but why should I use SendInput? What DLL is
that called from? I had some help from some friends and got my issues
figured out.

All of this goes in Form1 : Form
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,
UIntPtr dwExtraInfo);
public const int KEYEVENTF_EXTENDEDKEY = 0x1;
public const int KEYEVENTF_KEYUP = 0x2;
public System.Byte Byte001;

This part goes into the button:
Byte001 = Convert.ToByte(Convert.ToInt16(textBox1.Text) + 48);

And this into the BackGroundWorker1 Do Work
keybd_event(Byte001, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
keybd_event(Byte001, 0x45, KEYEVENTF_EXTENDEDKEY |
KEYEVENTF_KEYUP, (UIntPtr)0);

I would like your feed back because I would like to know what bugs I may have.
Thank you,
Chris
Mar 7 '06 #3
Chris,

SendInput is in user32.dll.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chris242" <Ch******@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...

Nicholas,

Sorry for such a silly question but why should I use SendInput? What DLL
is
that called from? I had some help from some friends and got my issues
figured out.

All of this goes in Form1 : Form
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,
UIntPtr dwExtraInfo);
public const int KEYEVENTF_EXTENDEDKEY = 0x1;
public const int KEYEVENTF_KEYUP = 0x2;
public System.Byte Byte001;

This part goes into the button:
Byte001 = Convert.ToByte(Convert.ToInt16(textBox1.Text) + 48);

And this into the BackGroundWorker1 Do Work
keybd_event(Byte001, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
keybd_event(Byte001, 0x45, KEYEVENTF_EXTENDEDKEY |
KEYEVENTF_KEYUP, (UIntPtr)0);

I would like your feed back because I would like to know what bugs I may
have.
Thank you,
Chris

Mar 7 '06 #4
Is there any reason this wouldn't work in all applications? It will work in
notepad and such but when I bring it into the application I want it to send
the key strokes to it doesn't pass the keys proprly. I can use another
application called AutoIT3 and get this to work just fine, but I would of
thought VC# would of not only done the job, but would have done it better.
Mar 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Erwin Bormans | last post by:
Hello I want to convert a value in a text propertie to a double. I can use CDbl(grid1.text) for this, but the problem is that some text properties are empty and when they are the code give...
3
by: mave | last post by:
Is anyone aware of a Java program preferably w/ source code to convert files in text format to xml format? Pls. let me know if you are aware of such a program.
4
by: Daniel Köster | last post by:
Is there someone who has got some tips on how to convert text encoded with character referense ({) to unicode or uft-8 format using VB.net? Is there a function or something that can help with the...
6
by: smilly | last post by:
This field is bound to a image data type in SQL server that is used to house big amounts of text how can I output the text data because right now I am getting System.Byte
4
by: Randel Bjorkquist | last post by:
I'm extremely new to C# and the Microsoft Visual Studio IDE. I'm writing a small web-application that executes a SQL Server stored procedure. For the most part, I have it working. I am at the...
7
by: ngocviet | last post by:
I have a text like this: "Thuyền Và Biển" How to convert it to: "Thuyá»n Và Biển" Please help!
2
by: comp.lang.php | last post by:
I am trying to replace within the HTML string $html the following: With Where I'm replacing "action=move_image" with "action=<?= $_REQUEST ?>"
1
by: rajendiran | last post by:
hi friends i will type any text in textbox. and chose any language that text will converted in that language example like english to french.. how to convert text like this anyone help me..........
15
by: pakerly | last post by:
How would i do this, convert a test file to excel? Lets say my text file has fields like this: NUMBER NAME ADDRESS PHONE 11002 Test1 ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.