PostKeybdMessage

  • Thread starter Robert Barreiro
  • Start date
R

Robert Barreiro

Hi everyone!

I'm developing a custom control for Windows Mobile which mimics the SIP
built-in keyboard, basically it's the same, but the difference is that I
need to be able to move it, displaying the keyboard on the bottom of the
screen, top, etc.

I'm using the PostKeybdMessage function to send the user selected key to the
active window, that's simple. But I have a problem: I can't send the arrows
keys (up, down, right, left). The codes are:

- Up: 38
- Down: 40
- Left: 37
- Right: 39

But these are the same codes for other characters, so when I'm sending that
codes I get the character representation (38=& - 39=( - 37=% - 39='). The
question is, what I'm doing wrong? Do I have to send another code too?

The code snippet I'm using for the SendKey function is something like this:

private void SendKey(byte key) {

uint KeyStateDownFlag = 0x0080;
uint KeyShiftDeadFlag = 0x20000;
uint[] buf1 = new uint[1];
uint[] DownStates = new uint[1];
DownStates[0]=KeyStateDownFlag;
buf1[0]=(uint)key;

uint[] DeadStates = {KeyShiftDeadFlag};

int hwnd = -1;

PostKeybdMessage(hwnd, 0, KeyStateDownFlag, (uint)buf1.Length,
DownStates, buf1);
}

I really appreciate your help, I'm kind of stuck with this :(


Regards,



Robert Barreiro.
 
P

Paul G. Tobey [eMVP]

You're doing it wrong. You're trying to send the *characters* 38, 39, etc.
Those are not characters (the arrows); they are *keys*. You can send the
virtual *key codes* for them, but if you try to send those values as
characters, as you see, you'll get something else.

Use keybd_event(), *not* PostKeybdMessage(), to send *keys* (Control, Alt,
Function, etc.)

Paul T.
 
A

Arun

You're doing it wrong.  You're trying to send the *characters* 38, 39, etc.  
Those are not characters (the arrows); they are *keys*.   You can send the
virtual *key codes* for them, but if you try to send those values as
characters, as you see, you'll get something else.

Use keybd_event(), *not* PostKeybdMessage(), to send *keys* (Control, Alt,
Function, etc.)

Paul T.



Robert Barreiro said:
Hi everyone!
I'm developing a custom control for Windows Mobile which mimics the SIP
built-in keyboard, basically it's the same, but the difference is that I
need to be able to move it, displaying the keyboard on the bottom of the
screen, top, etc.
I'm using the PostKeybdMessage function to send the user selected key to the
active window, that's simple. But I have a problem: I can't send the arrows
keys (up, down, right, left). The codes are:
- Up: 38
- Down: 40
- Left: 37
- Right: 39
But these are the same codes for other characters, so when I'm sending that
codes I get the character representation (38=& - 39=( - 37=% - 39='). The
question is, what I'm doing wrong? Do I have to send another code too?
The code snippet I'm using for the SendKey function is something like this:
private void SendKey(byte key) {
            uint KeyStateDownFlag = 0x0080;
            uint KeyShiftDeadFlag = 0x20000;
            uint[] buf1 = new uint[1];
            uint[] DownStates = new uint[1];
            DownStates[0]=KeyStateDownFlag;
            buf1[0]=(uint)key;
            uint[] DeadStates = {KeyShiftDeadFlag};
            int hwnd = -1;
            PostKeybdMessage(hwnd, 0, KeyStateDownFlag, (uint)buf1.Length,
DownStates, buf1);
        }
I really appreciate your help, I'm kind of stuck with this :(

Robert Barreiro.

Yes, use keybd_event()
const byte KEYEVENTF_SILENT = 0x0004;
keybd_event((byte)Keys.Down, 0, KEYEVENTF_SILENT, UIntPtr.Zero);
keybd_event((byte)Keys.Up, 0, KEYEVENTF_SILENT, UIntPtr.Zero);

[DllImport("coredll.dll", EntryPoint="keybd_event")]
private static extern void keybd_event(byte bVk, byte bScan, uint
dwFlags, UIntPtr dwExtraInfo);

Hope this helps,

Cheers,
Arun Selvaraj
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top