Console SendKey issue.

So, I have this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include <stdio.h>

void SendKey (char Vk) 
{
char VkKey = VkKeyScan(Vk);
keybd_event(VK_SHIFT, 0, 0, 0);
keybd_event(VkKey, 0, 0, 0); 
keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VkKey, 0, KEYEVENTF_KEYUP, 0);
}
using namespace std;

int main(int argc, char *argv[])
{
    FILE * pFile;
    char myString[100];
    
    _sleep(3000);   
    
    pFile = fopen("test.txt", "r+");
    if(pFile == NULL) perror("Error opening File");
    else {
         while(!feof(pFile)) {
              fgets(myString, 100, pFile);
              for(int i = 0; i < sizeof myString; i++) {
                 SendKey(myString[i]);
                 }  
              keybd_event(VK_RETURN,0,0,0); 
              keybd_event(VK_RETURN,0, KEYEVENTF_KEYUP, 0);
              _sleep(1000);
         }     
         }
    system("PAUSE");
    return EXIT_SUCCESS;
}


Basically, I just want it to read the text from a file and send it to whichever program I have selected.
I think there is a problem while reading/sending, cuz if the text is this:
1
2
3
4
5
6
:):):)            :)    :):):)     :)         :)
  :)             :)                  :)     :)         :)
  :)        :)              :):):)     :)         :)
  :)             :)                  :)     :)         :)
  :)             :)                  :)     :)         :)
:):):)             :)   :):):)     :):):):)


In Notepad or whatever I get this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14

:):):)            :)    :):):)     :)         :)
@"@B@@@"W:)FWGW)P{@O{@*"@}GW@@@@
  :)             :)                  :)     :)         :)
@W:)FWGW)P{@O{@*"@}GW@@@@
  :)        :)              :):):)     :)         :)
@ :)
@W:)FWGW)P{@O{@*"@}GW@@@@
  :)             :)                  :)     :)         :)
@W:)FWGW)P{@O{@*"@}GW@@@@
  :)             :)                  :)     :)         :)
@W:)FWGW)P{@O{@*"@}GW@@@@
:):):)             :)   :):):)     :):):):)@:)         :)
@W:)FWGW)P{@O{@*"@}GW@@@@


What's with the whole @, F, W, G, and other signs? I can't really understand...
Thank you for your time!
Last edited on
You can't use sizeof to get the length of the string. It gives you the size of the physical buffer (in this case, 100). Your actual string is much smaller than that.

use strlen(myString) instead.
Last edited on
Thank you for the quick answer! That worked like a charm!
Thank you again! xD
Topic archived. No new replies allowed.