Qbasicnews.com

Full Version: VB6 Replace Keystroke
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hiya! I know how to get a keystroke from anywhere but how do I replace it with soemthing?


Like I type

a

but it shows up

b



Thanks!

EDIT: BTW this is anywhere

So if I type 'a' in the address bar it says 'b'
You can try using SendKeys... Big Grin
does that replace it or just add to it?

so if I type 'a' would it spit out 'ab'?
If you write a keyboard hook, then you should in theory be able to change the value of the keypress. In your windows hook function, you will be passed information about the key that was pressed. If you modify this value, then call CallNextHookEx with the modified value, then return 0 from your routine, the target window should end up receiving your modified value.

I'm not sure whether this would work, but it's worth a shot.

-shiftLynx
EDIT::: Sorry...I didn't read the subject and didn't realize this was a VB6 Question...please ignore my response. Mango

Quote:Hiya! I know how to get a keystroke from anywhere but how do I replace it with soemthing?


Like I type

a

but it shows up

b



Thanks!

EDIT: BTW this is anywhere

So if I type 'a' in the address bar it says 'b'

well...if you add 1 to the value of the keystroke, it should do what you want. However, based on your EDIT, i'm not sure I get what you're after.

Code:
#include <windows.h>
#include <iostream>
using namespace std;
int main() {
    CHAR buffer[1] = "";
    DWORD w;
    HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
    HANDLE keyboard = GetStdHandle(STD_INPUT_HANDLE);
    INPUT_RECORD input[1];
    do {
        // Read an input record.
        ReadConsoleInput(keyboard, input, 1, &w);
        
        // Process a key down input event.
        if (input[0].EventType == KEY_EVENT
        && input[0].Event.KeyEvent.bKeyDown) {
        
            // Retrieve the character that was pressed.
            buffer[0] = input[0].Event.KeyEvent.uChar.AsciiChar;
            buffer[0] += 1;
            
            // Echo this character to the middle of the console.
            WriteConsoleOutputCharacter(console, buffer, 1,
            (COORD){35, 12}, &w);
            
            
        }
    } while (buffer[0] != 'x');
}