Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ convert character array to uppercase ( no MFC )
    primarykey
    data
    text
    <p>I am trying to get my application to convert a character array to uppercase letter so I can pass them as key presses. I know I am close to getting this code working but I just cant see the problem.</p> <pre><code> int a, b, c, d; char text[25]; char upper[25]; for (a = 0, b = sizeof(login); a &lt; b; a++) { if (isalpha(login[a])){ l[a] = toupper(login[a]); Sleep(1000); GenerateKey(l[a], FALSE);} else{ GenerateKey(l[a], FALSE); Sleep(1000); l[a] = login[a];} } login[a]='\0'; GenerateKey(0x09, FALSE); for (c = 0, d = sizeof(pass); c &lt; d; c++) { if (isalpha(pass[c])){ p[c] = toupper(pass[c]); GenerateKey(p[c], FALSE); Sleep(1000);} else{ GenerateKey(p[c], FALSE); p[c] = pass[c]; Sleep(1000);} } pass[a]='\0'; GenerateKey(0x09, FALSE); Sleep(1000); GenerateKey(0x09, FALSE); Sleep(1000); GenerateKey(0x0D, FALSE); </code></pre> <p>And here is the GenerateKey function:</p> <pre><code>void GenerateKey(int vk, BOOL bExtended) { KEYBDINPUT kb = {0}; INPUT Input = {0}; /* Generate a "key down" */ if (bExtended) { kb.dwFlags = KEYEVENTF_EXTENDEDKEY; } kb.wVk = vk; Input.type = INPUT_KEYBOARD; Input.ki = kb; SendInput(1, &amp;Input, sizeof(Input)); /* Generate a "key up" */ ZeroMemory(&amp;kb, sizeof(KEYBDINPUT)); ZeroMemory(&amp;Input, sizeof(INPUT)); kb.dwFlags = KEYEVENTF_KEYUP; if (bExtended) { kb.dwFlags |= KEYEVENTF_EXTENDEDKEY; } kb.wVk = vk; Input.type = INPUT_KEYBOARD; Input.ki = kb; SendInput(1, &amp;Input, sizeof(Input)); return; } </code></pre> <p>Any help would be great!</p> <p><strong>EDIT:</strong></p> <p>This appplication is trying to open a webpage and then enter login information and press submit(using tab to select the username, password fields, etc). To answer @Rup, <code>l[]</code> and <code>p[]</code> are initialised above this block of code.</p> <pre><code> char l[180]; char p[180]; </code></pre> <p>l is the users login name and p is their password. I am trying to convert these to uppercase to pass them in GenerateKey. eg <code>GenerateKey('A', FALSE);</code></p> <p>At the moment the code does not seem to pass any keypresses at all but the application freezes so I believe it is getting stuck in a for loop somewhere.</p> <p><strong>EDIT 2:</strong></p> <p>Thanks to @William for providing the helpful code. Using the toUpper function I am very close to solving this issue. The only issue I am having now is that the login and password being passed contain extra characters. For example if I pass login as <code>username</code>, then rerun the program and pass login as <code>user</code> I get the output <code>userame</code>.</p> <p>This is the code I have now with the GenerateKey and toUpper functions:</p> <pre><code> // Convert to uppercase to be passed as keypresses toUpper(login, sizeof(login)); toUpper(pass, sizeof(pass)); int a; for(a=0; a&lt;sizeof(login);a++){ GenerateKey(login[a], FALSE);} login[a]='\0'; GenerateKey(0x09, FALSE); a=0; for(a=0; a&lt;sizeof(pass);a++){ GenerateKey(pass[a], FALSE);} pass[a]='\0'; GenerateKey(0x09, FALSE); Sleep(1000); GenerateKey(0x09, FALSE); Sleep(1000); GenerateKey(0x0D, FALSE); </code></pre> <p><strong>SOLUTION:</strong></p> <p>Using <code>strlen(login);</code> in the above code cleared up all hte issues I was having. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload