Search code examples
mobilewindows-mobilewindows-mobile-6.5honeywell

How to send key combination / Windows Mobile 6.5


I´ve got a windows mobile 6.5 device (Honeywell) in combination with SOTI. What I need to implement is, that, if the device has a akku status <10 percent, it should shutdown. That is the part I can do with SOTI.

Before this shutdown I need to send the F12-key five times. How can I realize that? I know that there a virtual key-codes (https://msdn.microsoft.com/en-us/library/ms927178.aspx) but I don´t know, how to trigger them.


Solution

  • You can use the keybd_event function

        keybd_event( VK_F12, 0, 0, 0 );
        keybd_event( VK_F12, 0, KEYEVENTF_KEYUP, 0 );
    

    To use that from .NET see pinvoke

        using System.Runtime.InteropServices;
        ...
        public const uint KEYEVENTF_KEYUP = 2;
        
        [DllImport("coredll.dll", EntryPoint = "keybd_event", SetLastError = true)]
        public static extern void keybd_event
        (
          byte bVk,
          byte bScan,
          int dwFlags,
          int dwExtraInfo
        );
    

    Always use two calls with the same key value, one for key dwon and one with KEYEVENTF_KEYUP.

    The bScan for the scan code can normally be 0 or you need to lookup the PS/2 keyboard scan codes for the key you send.