博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Mobile 模拟按键

Posted on 2009-05-20 21:50  脚印  阅读(1409)  评论(0编辑  收藏  举报

public const byte VK_NONAME = 0xFC; // 什么也不做
        public const byte VK_ESC = 0x1B; // Smartphone的回退键
        public const byte VK_F4 = 0x73; // Home Screen
        public const byte VK_APP6 = 0xC6; // Smartphone上锁定键盘
        public const byte VK_F22 = 0x85; // PocketPC上锁定键盘(VK_KEYLOCK)
        public const byte VK_F16 = 0x7F; // 出发扬声器
        public const byte VK_OFF = 0x7F; //电源键
        public const byte VK_TSOFT1 = 0x70;
        public const byte VK_TSOFT2 = 0x71;
        public const byte VK_TTALK = 0x72;
        public const byte VK_TEND = 0x73;

  /// <summary>
        /// 将按键送至全局键盘缓冲区
        /// </summary>
        /// <param name="key"></param>

        public static void SendKey(byte key)
        {
            //const byte KEYEVENTF_SILENT = 0x0004;
            const int KEYEVENTF_KEYUP = 0x02;
            const int KEYEVENTF_KEYDOWN = 0x00;
            keybd_event(key, 0, KEYEVENTF_KEYDOWN, 0);
            keybd_event(key, 0, KEYEVENTF_KEYUP, 0);
        }

        [DllImport("coredll", SetLastError = true)]
        private static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

 private void button1_Click(object sender, EventArgs e)
        {
            SendKey(VK_TTALK);
        }



Windows Mobile maintains a device–independent keyboard model that enables it to support a variety of keyboards. At the lowest level, each key on the keyboard generates a scan code when the key is pressed and released. The scan code is a hardware–dependent number that identifies the key. The keyboard driver translates or maps each scan code to a virtual key code. The virtual key code is a hardware–independent hexadecimal number that identifies the key. Because keyboard layouts vary from language to language, Windows Mobile offers only the core set of virtual key codes that are found on all keyboards. This core set includes English characters, numbers, and a few critical keys, such as the function and arrow keys. Keys that are not included in the core set also have virtual key code assignments, but their values vary from one keyboard layout to the next. You should depend only on the virtual key codes that are in the core set.

The following table shows the symbolic constant names, hexadecimal values, and keyboard equivalents for the virtual key codes used by the Windows Mobile operating system. The codes are listed in numeric order. You can combine any of the codes with a modifier key to create a hot key.

A VK_code is a byte, and so there are only 256 VK_codes total. The virtual key codes listed in the "Virtual key codes" section below are shared with Windows Embedded CE. More virtual keys were required for functionality, and so many hex values are shared between both a traditional Windows Embedded CE value and a Windows Mobile–specific value.

The following table provides a list of the mappings between the traditional VK constants and the additional Windows Mobile–specific value.

Hexadecimal value Windows Embedded CE constant Shared Windows Mobile constant Windows Mobile purpose

0x08

VK_BACK

VK_TBACK

Back.

0x0D

VK_RETURN

VK_TACTION

Action.

0x25

VK_LEFT

VK_TLEFT 

Left.

0x26

VK_UP

VK_TUP

Up.

0x27

VK_RIGHT

VK_TRIGHT

Right.

0x28

VK_DOWN

VK_TDOWN

Down.

0x5B

VK_LWIN

VK_THOME

Home screen or Today screen

0x70

VK_F1

VK_TSOFT1

Softkey 1.

0x71

VK_F2

VK_TSOFT2

Softkey 2.

0x72

VK_F3

VK_TTALK

Talk

0x73

VK_F4

VK_TEND

End

0x75

VK_F6

VK_TVOLUMEUP

Volume Up.

0x76

VK_F7

VK_TVOLUMEDOWN

Volume Down.

0x77

VK_F8

VK_TSTAR

*

0x78

VK_F9

VK_TPOUND

#

0x79

VK_F10

VK_TRECORD

Record.

0x7A

VK_F11

VK_SYMBOL

Symbol (SYM) key.

0x7E

VK_F15

VK_END_ALL_DATA_CALLS

Disconnects all data calls without affecting the status of voice calls.

0x7F

VK_F16

VK_TSPEAKERPHONE_TOGGLE

Toggles speakerphone on and off.

0x80

VK_F17

VK_TFLIP

Flip.

0x81

VK_F18

VK_TPOWER

Power.

0x82

VK_F19

VK_REDKEY

Sent by a keypad that has a special red function key.

0x83

VK_F20

VK_ROCKER

Arrow keys came from a Rocker.

0x84

VK_F21

VK_DPAD

Arrow keys came from a d–pad.

0x85

VK_F22

VK_KEYLOCK

Key used to lock device.

0x86

VK_F23

VK_ACTION

Sent with VK_RETURN when doing Action on Windows Mobile 6 Classic rockers.

0x87

VK_F24

VK_VOICEDIAL

Key used to kick off voice dial recognition.

For more information about the d-pad, see D-pad Virtual Key Code Support. For more information about soft keys, see Soft Key Virtual Key Codes.

The following keys were undefined for Windows Embedded CE, but are overridden as application keys in Windows Mobile.

Hexadecimal value Windows Mobile constant

0xC1

VK_APP_FIRST

0xC1

VK_APP1

0xC2

VK_APP2

0xC3

VK_APP3

0xC4

VK_APP4

0xC5

VK_APP5

0xC6

VK_APP6

0xC6

VK_APP_LAST

The VK_APP keys will only be recognized by the system if they are wrapped with VK_LWIN. The following code snippet demonstrates how to do this programmatically.

keybd_event(VK_LWIN, 0, KEYEVENTF_SILENT, 0);
GenKeyEvent(VK_APP1);
keybd_event(VK_LWIN, 0, KEYEVENTF_SILENT | KEYEVENTF_KEYUP, 0);