programmaticly remap keyboard

  • hi all,

    how can I remap the F1 - F4 keys programmatcily?

    I find out to delete the current Items , but can't make new ones ?!

     

    Delete

     

     

     

     

     

     

     

     

    If

     

     

    iCount > 0

    Then

     

     

    For iTeller = (iCount - 1) To 0 Step

    -1

    oKey =

     

    CType

    (oKeys.NormalTable.Entries.Item(iTeller), PsionTeklogix.Keyboard.NoChording.RemappingTable.TableEntry)

     

     

    Select Case

    oKey.ScanCode

     

     

    Case

    AlfaPsionKeyboardScanCode.F1, AlfaPsionKeyboardScanCode.F2, AlfaPsionKeyboardScanCode.F3, AlfaPsionKeyboardScanCode.F4

    oKeys.NormalTable.Remove(oKey.ScanCode)

     

     

    Case

    Else ' nothing to do

     

     

     

     

    End

    Select

     

     

    Next

  • Good morning Wim,

    Which device / keybaord layout / keys are we talking about here?

     

    In case it helps, let me share the following code snippet with you

    Imports PsionTeklogix.Keyboard

     

    […]

     

        Private kr As KeyRemapper = Nothing

     

    […]

            Try

                kr = New KeyRemapper()

            Catch ex As Exception

                MessageBox.Show("KeyRemapper instantiation failed with" + vbCrLf + ex.Message)

                Me.Close()

                Return

            End Try

     

            Try

                'Remap [ F1 ] to [ A ]

                kr.Add(Keyboard.TranslateToScanCode(Key.F1), Nothing, [Function].SendCode, VirtualKey.VK_A)

                ' Remap [ FN Blue ] [ 1 ] to [ A ]

                kr.Add(Keyboard.TranslateToScanCode(Key.key1), Key.Blue, [Function].SendCode, VirtualKey.VK_A)

            Catch ex As Exception

                MessageBox.Show("Adding new remapping failed with" + vbCrLf + ex.Message)

            End Try

     

    […]

     

            kr.RemoveAll()

    I do hope this helps.
    Kind regards,

    Jacques

  • Problem Solved

    Thanks

  • It is  for the WorkAbout Pro G3 version because the keyboard layout changed  (too much in my opinion)

    I build an application where users can give in a lot of prices, contents of packaging (in kilograms) where they have to use the decimals sign a lot. Also the Enter key is very small. I (we) prefer the ‘old’ G2 keyboard layout.

    Also I made ‘speed’ choice keys by using the ALT key like you do in Windows .

    And they always in a hurry, Flower Wholesales!

    With the new keyboard layout you’ve first to press a blue key which make the user have to  press at least one key more for a price or contents or whatever.

    But to the point, I just managed to find the right code to remap the keys.

     

    F1 will be ESCAPE

    F2 will be ALT

    F3 will be COMMA

    F4 will be DECIMAL

     

    Thanks for the quick reply!

     

    Ps.

    No Keyboard.TransLateToScanCode()  !!

    I’m using SDK 3.4, Vis.Studio 2008, VB

     

     

    Source:

     

    Public Enum AlfaPsionKeyboardScanCode

           F1 = 7  ' Hex 7

           F2 = 15 ' Hex F

           F3 = 6  ' Hex 6

           F4 = 20 ' Hex 14

    End Enum

     

     

    Private Sub test2()

           Dim oKeys As PsionTeklogix.Keyboard.NoChording.ScanCodeRemapping

           Dim oKey As PsionTeklogix.Keyboard.NoChording.RemappingTable.TableEntry

           Dim iCount As Integer = oKeys.NormalTable.Entries.Count

           If iCount > 0 Then

                 For iTeller = (iCount - 1) To 0 Step -1

                        oKey = CType(oKeys.NormalTable.Entries.Item(iTeller), PsionTeklogix.Keyboard.NoChording.RemappingTable.TableEntry)

                        Select Case oKey.ScanCode

                               Case AlfaPsionKeyboardScanCode.F1, AlfaPsionKeyboardScanCode.F2, AlfaPsionKeyboardScanCode.F3, AlfaPsionKeyboardScanCode.F4

                                      oKeys.NormalTable.Remove(oKey.ScanCode)

                               Case Else

                                      ' Intact laten!!

                        End Select

                 Next

           End If

     

           Dim oNewKey As PsionTeklogix.Keyboard.NoChording.ScanCodeRemapping

           Dim oNewKeyMapping As PsionTeklogix.Keyboard.NoChording.RemappingTable.Remapping

           Try

                 oNewKeyMapping = New PsionTeklogix.Keyboard.NoChording.RemappingTable.Remapping(PsionTeklogix.Keyboard.VirtualKey.VK_ESCAPE)

                 oNewKey.NormalTable.Add(Convert.ToUInt16(AlfaPsionKeyboardScanCode.F1), oNewKeyMapping)

     

                 oNewKeyMapping = New PsionTeklogix.Keyboard.NoChording.RemappingTable.Remapping(PsionTeklogix.Keyboard.Function.Alt)

                 oNewKey.NormalTable.Add(Convert.ToUInt16(AlfaPsionKeyboardScanCode.F2), oNewKeyMapping)

     

                 oNewKeyMapping = New PsionTeklogix.Keyboard.NoChording.RemappingTable.Remapping(PsionTeklogix.Keyboard.VirtualKey.VK_COMMA, PsionTeklogix.Keyboard.Function.SendUnshiftedCode)

                 oNewKey.NormalTable.Add(Convert.ToUInt16(AlfaPsionKeyboardScanCode.F3), oNewKeyMapping)

     

                 oNewKeyMapping = New PsionTeklogix.Keyboard.NoChording.RemappingTable.Remapping(PsionTeklogix.Keyboard.VirtualKey.VK_DECIMAL, PsionTeklogix.Keyboard.Function.SendUnshiftedCode)

                 oNewKey.NormalTable.Add(Convert.ToUInt16(AlfaPsionKeyboardScanCode.F4), oNewKeyMapping)

     

           Catch ex As Exception

           End Try

           oNewKey = Nothing

           oNewKeyMapping = Nothing

           oKeys = Nothing

           oKey = Nothing

    End Sub

  • Wim,

    Thanks for the follow up and update.

    This said, to remap keys, I would strongly recommend using the KeyRemapper class - like illustrated in the code snippet I shared with your earlier - as the Keyboard:.NoChroding namespace has been deprecated.

    Regards,
    Jacques

    --

    For your information, the TranslateToScancode function belongs to the PsionTeklogix.Keyboard namespace

    Public Shared Function TranslateToScanCode(ByVal key As

    PsionTeklogix.Keyboard.Key) As Integer
    Member of PsionTeklogix.Keyboard.Keyboard

    Translates a device-independent key value (enum Key) to a device-dependent scan code that may be used with other keyboard API functions.

    Parameters:
    key: [in] Key enum value that specifies the key to be translated. PsionTeklogix.Keyboard.Key

    Return Values:
    The device dependent scan code. If device doesn't have this key, it will return ScanCodeNotFound constant.

  •  

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    Hi Jacques,

    the source under, is like yours, will first remove all already set keys I want to remap and then set the new ones.

    But after set the new mappings they won't appaer in the Settings->Buttons->ScanCodeRemapping screen. AND they won't work. Therefor i choose to use the other function.

     

    Private

     

    Sub RemapKeysBasic()

     

    Dim oKeys As PsionTeklogix.Keyboard.KeyRemapper

     

    Dim oKey As PsionTeklogix.Keyboard.KeyRemapper.KeyRemapping

     

    Dim newValue As String = ""

     

    Dim aKeys As Array = Nothing

     

    Try

    oKeys =

    New PsionTeklogix.Keyboard.KeyRemapper

     

    Catch ex As Exception

    MsgBox(

    "KeyRemapper failed tio instatiate " + ex.Message)

     

    Return

     

    End Try

    aKeys = oKeys.GetAllKeyRemappings()

     

    If aKeys IsNot Nothing Then

     

    For Each oKey In aKeys 'oKeys.GetAllKeyRemappings

     

    Select Case oKey.scanCode

     

    Case PsionTeklogix.Keyboard.Keyboard.TranslateToScanCode(PsionTeklogix.Keyboard.Key.F1), PsionTeklogix.Keyboard.Keyboard.TranslateToScanCode(PsionTeklogix.Keyboard.Key.F2), PsionTeklogix.Keyboard.Keyboard.TranslateToScanCode(PsionTeklogix.Keyboard.Key.F3), PsionTeklogix.Keyboard.Keyboard.TranslateToScanCode(PsionTeklogix.Keyboard.Key.F4)

    oKeys.Remove(oKey.scanCode, oKey.modifier)

     

    Case Else

     

    ' Intact laten!!

     

    End Select

     

    Next

     

    End If

    'Set teh new keys

     

    Try

    oKeys.Add(PsionTeklogix.Keyboard.Keyboard.TranslateToScanCode(PsionTeklogix.Keyboard.Key.F1),

    Nothing, PsionTeklogix.Keyboard.Function.FunctionTrigger, PsionTeklogix.Keyboard.VirtualKey.VK_ESCAPE) 'Doe alsof je een ESCAPE bent

    oKeys.Add(PsionTeklogix.Keyboard.Keyboard.TranslateToScanCode(PsionTeklogix.Keyboard.Key.F2),

    Nothing, PsionTeklogix.Keyboard.Function.Alt, 0)

    oKeys.Add(PsionTeklogix.Keyboard.Keyboard.TranslateToScanCode(PsionTeklogix.Keyboard.Key.F3),

    Nothing, PsionTeklogix.Keyboard.Function.SendUnshiftedCode, PsionTeklogix.Keyboard.VirtualKey.VK_COMMA) 'Doe alsof je een KOMMA bent

    oKeys.Add(PsionTeklogix.Keyboard.Keyboard.TranslateToScanCode(PsionTeklogix.Keyboard.Key.F4),

    Nothing, PsionTeklogix.Keyboard.Function.SendUnshiftedCode, PsionTeklogix.Keyboard.VirtualKey.VK_DECIMAL) 'Doe alsof je een PUNTbent

     

    Catch ex As Exception

     

    End Try

    oKeys =

    Nothing

    oKey =

    Nothing

     

    End Sub

     

     

  • Good morning Wim,

    In case it helps, I am attaching to this note a VS2008 VB .NET solution that illustrates how to programmatically remap the WAP3 top bezel [F1] [F2] [F3] and [F4] keys to respectively [ESC] [ALT] [,] and [.]

     

     MDSDK v3.4 - VS2008 VB .NET Remap F1 Thru F4 demo solution.zip

    --

    For your information, remapping the WAP3 top bezel F1 thru f4 keys is done as follows:

    Private Sub chkRemap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkRemap.Click

        If (chkRemap.Checked) Then

            'Remap the WAP3 top bezel [F1] [F2] [F3] and [F4] to respectively [ESC] [ALT] [,] and [.]

            Try

                kr.Add(Keyboard.TranslateToScanCode(Key.F1), Nothing, [Function].SendCode, VirtualKey.VK_ESCAPE)

                kr.Add(Keyboard.TranslateToScanCode(Key.F2), Nothing, [Function].Alt, Nothing)

                kr.Add(Keyboard.TranslateToScanCode(Key.F3), Nothing, [Function].SendCode, VirtualKey.VK_COMMA)

                kr.Add(Keyboard.TranslateToScanCode(Key.F4), Nothing, [Function].SendCode, VirtualKey.VK_DECIMAL)

            Catch ex As Exception

                MessageBox.Show("Adding new remapping failed with" + vbCrLf + ex.Message)

            End Try

        Else

            Try

                kr.Restore()

            Catch ex As Exception

                MessageBox.Show("Restoring remapping failed with" + vbCrLf + ex.Message)

            End Try

        End If

     

    End Sub

    I do hope this helps.
    Kind regards,

    Jacques