Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Recording what user types, for chat

  1. #1

    Recording what user types, for chat

    System: Windows Vista, Intel Centrino Duo 2.16, Nvidia GeForce 7950 512mb, 2048mb ram
    Compiler/IDE: BDS 2006
    Using: UnDelphiX

    Problem: How to get string input for chat?

    I have a timer that updates the inputstates every 33 ms, wich works for movement and short commands, but how can i make a input for a string??

    Diaboli...

  2. #2

    Recording what user types, for chat

    Hello!

    Just store each ascii representation of each key in a string to start. Something like:

    line := line+asciiKey;

  3. #3

    Recording what user types, for chat

    well, that easy to imagine (as it is how i thought of it), but i dont actually HAVE the ascii representation of any keys...

    the program check keystates every 33 milliseconds, not with a onkeydown event... (as i have been using for this kind of thing in the past...)

  4. #4

    Recording what user types, for chat

    How does it check the states, does it scans all the keys from 0 to 255? If so, just make an array that matches every key number to the corresponding ascii code and get the ascii value from it.

  5. #5

    Recording what user types, for chat

    there is this:
    Input.Keyboard.Keys: Array of Boolean

    but i dont know what integers are wich letters...

  6. #6

    Recording what user types, for chat

    Take a look at: http://msdn2.microsoft.com/en-us/library/bb174685.aspx

    There is the whole list in order from 0 to 255. Just make you array in such way that it matches those ascii codes, like this:

    const
    AsciiKey : array[0..255] of Char =
    '0', // DIK_0,
    '1', // DIK_1,
    '2', // DIK_2,
    '3', // DIK_3,
    '4', // DIK_4,
    '5', // DIK_5,
    '6', // DIK_6,
    '7', // DIK_7,
    '8', // DIK_8,
    '9', // DIK_9,
    'A', // DIK_A,
    #0, // DIK_ABNT_C1,
    #0, // DIK_ABNT_C2,
    ... etc

    Those with value of #0 don't have ascii code. To convert your codes to Ascii just index the array with the code of which key you are getting a press.

  7. #7

    re-

    however just cheking the keystate in a timer seem is not a readeable way to get the string the user is typing; most likely you will get a string like "tthisss iss aaa tteesst sstriinngg"; you have to take note when the key is realeased before recording again that key...still there is the problem about replicate key rate.

  8. #8

    Recording what user types, for chat

    tpascal: u have a very good point... i would much rather have some kind of keyup or keypress event, but how can i make that?

    like: how do you get the players name in your highscore-lists and such? there you must have the kind of code i need...

  9. #9

    Recording what user types, for chat

    Making one of those grids to enter the highscore is a little easier to build, but you still need to solve the same problems you will find making an input field.

  10. #10

    Recording what user types, for chat

    Quote Originally Posted by cronodragon
    Take a look at: http://msdn2.microsoft.com/en-us/library/bb174685.aspx

    There is the whole list in order from 0 to 255. Just make you array in such way that it matches those ascii codes, like this:

    const
    AsciiKey : array[0..255] of Char =
    '0', // DIK_0,
    '1', // DIK_1,
    '2', // DIK_2,
    '3', // DIK_3,
    '4', // DIK_4,
    '5', // DIK_5,
    '6', // DIK_6,
    '7', // DIK_7,
    '8', // DIK_8,
    '9', // DIK_9,
    'A', // DIK_A,
    #0, // DIK_ABNT_C1,
    #0, // DIK_ABNT_C2,
    ... etc

    Those with value of #0 don't have ascii code. To convert your codes to Ascii just index the array with the code of which key you are getting a press.
    That is unnecessary since chr(byte) already tells what each ascii number means as a letter.

    You said Input.Keyboard.Keys so i assume keys are read with (un)DelphiX. Anyway this is 1 way of making key down and up events:
    [pascal]// Used variables:
    var
    keyDown: array[0..255] of boolean;
    i: integer;
    chatLine: string;

    ...
    with Input.Keyboard do
    for i:=0 to 255 do
    if keys[i] and (not keyDown[i]) then begin
    keyDown[i]:=true; // KeyDown here

    // Simple input processing (0..31 are not really characters)
    if i in [32..255] then
    chatLine:=chatLine+chr(i);

    end else if (not keys[i]) and keyDown[i] then begin
    keyDown[i]:=false; // KeyUp here

    end;[/pascal]

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •