1

I have created xml file in which I have added all keys as nodes and its respective virtual key codes as a value. I am fetching those values and storing it in string format. I need output as: When I press key 0 its corresponding value is 0x30 But my PressKey function uses Keybd_event which takes virtual key code as an argument.

public bool Presskey(byte buttonVirtualKey)
{
   keybd_event(buttonVirtualKey, 0, 0, 0);
}

I need to convert the string formatted virtual key code("0x30") to byte value(0x30).

Any type of help would be appreciated.

1 Answer 1

1

We cannot convert string of form "0x30" to bytes because the Convert class expects a string of the form "30" to be able to convert. Also, the Convert class uses decimal base and not hexa-decimal. So, you first have to convert "30" to decimal value, and then use the decimal value in Convert.ToBytes(int) function, eg:

int decValue = int.Parse("30", System.Globalization.NumberStyles.HexNumber);
Convert.ToByte(decValue);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.