fb:porticula NoPaste
COM-Tastatur
Uploader: | Sebastian |
Datum/Zeit: | 05.04.2009 23:04:41 |
' Code-Vorschlag für Forenbeitrag
' http://forum.qbasic.at/viewtopic.php?t=6412
#include "windows.bi"
DECLARE SUB Tastendruck(ByVal KeyCode As UByte)
DIM SHARED KeyState(0 to 255) As Byte
DIM AS STRING Puffer
DIM AS UBYTE B, KeyCode, Extras
DIM AS INTEGER i = 0
DIM AS SHORT res
If (Open Com ( "COM1:9600,N,8,1,ME,CS0,DS0,RS" For Binary As #1 ) <> 0 ) Then
Print "Der Port konnte nicht geöffnet werden!"
Sleep: End
Else
Print "COM-Port geoeffnet"
End If
DO
If Loc(1) > 0 Then
Puffer = Space(Loc(1))
Get #1, , Puffer
For i = 0 TO LEN(Puffer)-1
B = Puffer[i]
res = VkKeyScan(B)
KeyCode = *(CAST(UBYTE PTR,@res))
Extras = (res AND (&B1111111100000000)) SHR 8
If (Extras AND 1) Then keybd_event (VK_SHIFT, &H45, KEYEVENTF_EXTENDEDKEY, 0)
If (Extras AND 2) Then keybd_event (VK_CONTROL, &H45, KEYEVENTF_EXTENDEDKEY, 0)
If (Extras AND 4) Then keybd_event (VK_MENU, &H45, KEYEVENTF_EXTENDEDKEY, 0)
Tastendruck (KeyCode)
If (Extras AND 1) Then keybd_event (VK_SHIFT, &H45, KEYEVENTF_EXTENDEDKEY OR KEYEVENTF_KEYUP, 0)
If (Extras AND 2) Then keybd_event (VK_CONTROL, &H45, KEYEVENTF_EXTENDEDKEY OR KEYEVENTF_KEYUP, 0)
If (Extras AND 4) Then keybd_event (VK_MENU, &H45, KEYEVENTF_EXTENDEDKEY OR KEYEVENTF_KEYUP, 0)
Next i
End If
Loop Until Inkey = Chr(27) 'Zum Beenden ESC druecken
End
SUB Tastendruck(ByVal KeyCode As UByte)
GetKeyboardState (@keyState(0))
if (NOT (keyState(KeyCode))) THEN
keybd_event ( KeyCode, &H45, KEYEVENTF_EXTENDEDKEY, 0 )
keybd_event ( KeyCode, &H45, KEYEVENTF_EXTENDEDKEY OR KEYEVENTF_KEYUP, 0)
END IF
END SUB