Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Sat Nov 18, 2017 10:28 am

All times are UTC - 7 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Register Events in C#
PostPosted: Wed Dec 16, 2009 1:29 pm 
Offline

Joined: Wed Dec 16, 2009 11:38 am
Posts: 9
Location: Buffalo, NY
What is the suggested way to register events or capture key presses on the 1-4 buttons on the TREQ-M4?

After reading through the TREQ-M4 documentation and the C# wrapper documentation, I can't seem to find an even somewhat straightforward way to do this.

Does anybody have a good C# example of this? I've tried a number of ways and have just found dead ends.


Top
 Profile  
 
PostPosted: Tue Dec 22, 2009 12:01 pm 
Offline

Joined: Wed Dec 16, 2009 11:38 am
Posts: 9
Location: Buffalo, NY
Does anyone have any insight in to this at all? Thanks.


Top
 Profile  
 
PostPosted: Thu Jan 14, 2010 11:02 am 
Offline
User avatar

Joined: Thu Jan 14, 2010 10:20 am
Posts: 38
If you are using the .NET wrappers, you could call the following method defined in TreqKeypadDriver.cs:

Code:
TreqKeypadDriver.SetKeypadKey(TreqKeys.TREQ_KEY0, exampleseq1, false);


Where:
TreqKeys.TREQ_KEY0 - is an enum also defined in TreqKeypadDriver.cs (where the other key defines exist also)
exampleseq1 - an array of 16-bit unsigned shorts you could use any of the following:
ushort[] exampleseq1 = { 0x70 }; //F1 key
(standard ce virtual key defines come from the SDK, or C:\Program Files\Windows CE Tools\wce600\TREQ-M4\Include\Armv4i\winuser.h starting at line 2956)
false - specifies to map the UNSHIFTED key to your value. For explation on shifted key state see M4 guide section 3.3)


For your sequence you can use other mappings also, for example you could use these:

Code:
ushort[] exampleseq2 = { (ushort)TreqVKCodes.VK_SEQ,(ushort)'B' }; //type the LOWERCASE character 'b'
ushort[] exampleseq2  = constructRunAppSeq("\\Windows\\explorer.exe");


The constructRunAppSeq method called is explained here:

Code:
        protected static ushort[] constructRunAppSeq(string program)
        {
            ushort[] runApp = new ushort[program.Length + 2];
            runApp[0] = (ushort)TreqVKCodes.VK_RUN_APP; //prepend runapp code
            runApp[program.Length + 1] = 0; //append null terminator
            program.ToCharArray().CopyTo(runApp, 1); //put string in the middle of the two
            return runApp;
        }


Please note that in order to assign a button to type the UPPERCASE character 'B' you would have to create a sequence which will press the virtual shift key, just as you would on a keyboard.

Finally, if you recall the C++ examples on page 50-51 of the M4 userguide, I've created a comparable version example in C#, the following method is a slice of that code:

Code:
private void chooseAssignment(int index, TreqKeys key, ref ushort[] keyval, bool shift)
        {
            switch (index)
            {
                case 0: //default
                    switch (key)
                    {
                        case TreqKeys.TREQ_KEY0:
                            if (shift) keyval = defaultKey1s; else keyval = defaultKey1; break;
                        case TreqKeys.TREQ_KEY1:
                            if (shift) keyval = defaultKey2s; else keyval = defaultKey2; break;
                        case TreqKeys.TREQ_KEY2:
                            if (shift) keyval = defaultKey3s; else keyval = defaultKey3; break;
                        case TreqKeys.TREQ_KEY3:
                            if (shift) keyval = defaultKey4s; else keyval = defaultKey4; break;
                    }
                    break;
                case 1: //runApp
                    // runApp launches MinTermCE.exe
                    keyval = constructRunAppSeq("\\HardDisk\\bin\\MinTermCE.exe");
                    break;
                case 2: //runSeq
                    // runSeq launches MinTermCE.exe, then types "done"
                    // Can't use string initializer when data follows the path in
                    // the sequence (compiler limitation)
                    ushort[] runSeq = { (ushort)TreqVKCodes.VK_SEQ | (ushort)TreqVKCodes.TREQ_KEY_REPEAT, (ushort)TreqVKCodes.VK_RUN_APP, '\\', 'H', 'a', 'r', 'd', 'D', 'i', 's', 'k', '\\', 'b', 'i', 'n', '\\', 'M', 'i', 'n', 'T', 'e', 'r', 'm', 'C', 'E', '.', 'e', 'x', 'e', 0, (ushort)'D', (ushort)'O', (ushort)'N', (ushort)'E' | (ushort)TreqVKCodes.TREQ_KEY_RELEASE };
                    keyval = runSeq;
                    break;
                case 3: //otherSeq
                    ushort[] otherSeq = { (ushort)TreqVKCodes.VK_SEQ | (ushort)TreqVKCodes.TREQ_KEY_REPEAT, (ushort)VKeys.VK_LSHIFT, (ushort)'H' | (ushort)TreqVKCodes.TREQ_KEY_RELEASE, (ushort)'E', (ushort)'L', (ushort)'L', (ushort)'O', (ushort)VKeys.VK_SPACE, (ushort)VKeys.VK_LSHIFT, (ushort)'W' | (ushort)TreqVKCodes.TREQ_KEY_RELEASE, (ushort)'O', (ushort)'R', (ushort)'L', (ushort)'D', (ushort)VKeys.VK_RETURN | (ushort)TreqVKCodes.TREQ_KEY_RELEASE };
                    keyval = otherSeq;
                    break;
            }
        }


Hopefully this helps.


Top
 Profile  
 
PostPosted: Fri Jan 22, 2010 8:24 am 
Offline

Joined: Fri Jun 05, 2009 2:29 pm
Posts: 3
If what you want to do is trap the keystrokes of the the keypad keys you'll have to invoke SetWindowsHookEx in coredll.dll. I used the technique in Prathamesh S Kulkarni's Code project article and made my own DLL and P/Invoked it from .NET. If you want to capture only the keypad keys, not from an attached keyboard, you have to examine the scan codes and key values to filter them - see KBDLLHOOKSTRUCT. I passed the window handle to the .NET window as a parameter in my P/Invoke call, and used that in the native side with PostMessage to generate WM_KEYDOWN and WM_KEYUP messages back to that window. You can also control whether to consume or simply get a copy of the keystroke based on calling CallNextHookEx or not. Then I simply handle the keystrokes as you would any keystroke in .NET. Note if your window already has focus, and you copy the keystroke, you'll get duplicate messages.

I noticed there is another approach entirely from .NET by hjgode, but my own attempts at a similar approach were unsuccessful, but I have not tried the code in hjgode's article.

Referenced Code Project Articles.
http://www.codeproject.com/KB/mobile/wincekbhook.aspx
http://www.codeproject.com/Articles/498 ... -fram.aspx


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group