Announcement

Collapse
No announcement yet.

WriteConsoleInput

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Semen Matusovski
    replied
    Eric --
    I was hurry. I need to investigate Word/dword and your suggestions.
    MSDN talks WORD then Bool.
    But I never had problems with DWORD + KEY_EVENTS.



    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Semen Matusovski
    replied
    I changed only WORD to DWORD.
    It's not 100% correct sample, because I don't fill wVirtualScanCode, but it works under Win2000.
    (guys, don't try to start under 9x)
    Code:
       #Compile Exe
       #Register None
       DefLng A-Z
    
       #Include "win32Api.inc"
    
       Function PbMain
          AllocConsole
          
          kStdIn = GetStdHandle(%STD_INPUT_HANDLE)
          ReDim InputRecords(1 To 100) As INPUT_RECORD
    
          i =  Shell ("SORT.Exe", 1): Sleep 1000
          w$ = "Semen" + $CRLF + "Peter" + $CRLF + Chr$(26) + $CR
          
          For i = 1 To Len(w$)
             Incr n
             InputRecords(n).EventType = %KEY_EVENT
             InputRecords(n).Event.keyEvent.bKeyDown = 1
             InputRecords(n).Event.keyEvent.wRepeatCount = 1
             InputRecords(n).Event.keyEvent.wVirtualScanCode  = 0 ' Use correct !
             InputRecords(n).Event.keyEvent.dwControlKeyState = 0
             inputRecords(n).Event.KeyEvent.uChar = Asc(Mid$(w$, i, 1))
             Incr n
             InputRecords(n) = InputRecords(n - 1)
             InputRecords(n).Event.keyEvent.bKeyDown = 0
          Next
          WriteConsoleInput kStdIn, InputRecords(1), n, n
    
          Sleep 2000
          FreeConsole
          
       End Function
    [This message has been edited by Semen Matusovski (edited October 24, 2000).]

    Leave a comment:


  • Eric Pearson
    replied
    Semen --

    That difference (WORD vs DWORD) is not a "terrible mistake". In fact, if you change DWORD to WORD you will find that the INPUT_RECORD structure will not work properly in all cases.

    The Win32 INPUT_RECORD structure must be DWORD aligned. So you can either 1) use WORD and add a "pad" WORD to create the correct alignment, or 2) use a DWORD for EventType (with no padding), or 3) use DWORD alignment (like TYPE INPUT_RECORD DWORD, which automatically pads the structure for you), in which case it makes no difference whether you use a WORD or DWORD.

    My personal preference is this:

    Code:
    TYPE INPUT_RECORD DWORD
      EventType AS WORD
      Event     AS EventStruc
    END TYPE
    But you must not DWORD-align the elements of the EventStruc UNION. They must be WORD-aligned. (Don't you just love the Win32 API?) Since the PB compilers default to BYTE alignment, and since none of the EventStruc elements contain BYTEs, the default result is correct.

    -- Eric


    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>



    [This message has been edited by Eric Pearson (edited October 24, 2000).]

    Leave a comment:


  • Semen Matusovski
    replied
    Peter --
    I took my PB CC program with own keyboard driver, cut a fragment.
    Works under PB/CC w/o problems.
    Moved to PB/DLL. And found that doesn't work.
    After changing to "C:\PbCC20... WinApi" - works.

    Reason --
    THERE ARE TERRIBLE MISTAKES IN PB/DLL WIN32API.INC.
    Code:
    TYPE INPUT_RECORD
      EventType AS WORD '<------------------------ DWORD !!!
      Event AS EventStruc
    END TYPE
    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Peter P Stephensen
    replied
    Keyboard



    ------------------

    Leave a comment:


  • Semen Matusovski
    replied
    Are you interesting in keyboard events or in mouse also ?

    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Peter P Stephensen
    started a topic WriteConsoleInput

    WriteConsoleInput

    Anybody got a working example of using WriteConsoleInput? It gives me
    a lot of problems.

    Regards
    Peter

    ------------------
Working...
X