keybd_event and RDP

Red Squirrel

No Lifer
May 24, 2003
70,203
13,588
126
www.anyf.ca
This is a weird one... so I have a program to automate a very tedious task that has to be done each day at work, and it's through a RDP session (the app runs on my PC). Suddenly, it stopped working. The RDP is no longer accepting the input. It makes the | cursor flash, so it's doing something, but not the proper keys. In the terminal (proprietary app) it shows up as giberish. So it's like if it's not sending the proper input and it's not translating through. My app has not changed, yet it stopped working.

This is the function used to send keys:

Code:
void PressKey(byte key,int delay)
{
	Core->Sleep(delay/2);
	keybd_event( key,0, KEYEVENTF_EXTENDEDKEY | 0,0 );
	Core->Sleep(delay/2);
    keybd_event( key,0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,0 );
}

Is there any reason why it would not work through RDP? I even tried to up the delay to like 300ms, still no go. I'm wondering if it's some kind of windows update that broke it. Is there a better way to do it? Worse case scenario I may have to make a mechanical bot of sort that sits on top of the keyboard. I want to avoid actually having to do that, there's got to be a way...
 

Red Squirrel

No Lifer
May 24, 2003
70,203
13,588
126
www.anyf.ca
Think I figured it out. I don't know why there's so much discretion and different ways of doing this, but found this way to work:

Code:
void PressKey(byte key,int delay)
{
	if(Core->Debug)cout<<"PressKey()";
	Core->Sleep(delay/2);
	
	int scan = MapVirtualKey(key & 0xff, 0);
	
	keybd_event( key,scan,0,0 );
	Wait(50000);
    keybd_event( key, scan,  KEYEVENTF_KEYUP, 0 );
}

No idea why it stopped working in first place, but it works now. o_O
 

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
Your original code was confusing because it is doing a bit comparison operation on the key. Not sure why it would need to do that. Is this C++?
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Your original code was confusing because it is doing a bit comparison operation on the key. Not sure why it would need to do that. Is this C++?

| is the bitwise OR operator, || is the comparison OR operator.

0x00F | 0x0F0 = 0x0FF
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Yeah... I said bit comparison...

There is a huge difference between comparing two bitstrings and running a bitwise OR on them.

I completely disagree that that operator should be a called a bitwise comparison. I would take the phrase bitwise comparison to mean the same thing as equality, after all you are comparing every single bit in the two objects.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
There is a huge difference between comparing two bitstrings and running a bitwise OR on them.

I completely disagree that that operator should be a called a bitwise comparison. I would take the phrase bitwise comparison to mean the same thing as equality, after all you are comparing every single bit in the two objects.

Agreed. It's not a comparison of any kind. It's a bitwise operator that takes two operands and produces a result.
 

sm625

Diamond Member
May 6, 2011
8,172
137
106
Those are flags. Its not comparing them it is just combining them.

Also, this statement is redundant:

KEYEVENTF_EXTENDEDKEY | 0

you can simply make it

KEYEVENTF_EXTENDEDKEY
 

Red Squirrel

No Lifer
May 24, 2003
70,203
13,588
126
www.anyf.ca
The previous code was just what I found online. The new code is something else I found online. I seem to have gotten it to work now. There's so many different flags and stuff with not so good documentation it's hard to know what most of them do or why they're needed.

Going to be running the app again tonight so hopefully I fixed it for good this time. :p
 

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
There is a huge difference between comparing two bitstrings and running a bitwise OR on them.

I completely disagree that that operator should be a called a bitwise comparison. I would take the phrase bitwise comparison to mean the same thing as equality, after all you are comparing every single bit in the two objects.

Agreed. It's not a comparison of any kind. It's a bitwise operator that takes two operands and produces a result.

Ok, I guess I just don't care enough. I knew what the operation was doing. It looks at the bits rather than the evaluation of the expression. In my mind that is comparing bits. My bad.

Those are flags. Its not comparing them it is just combining them.

Also, this statement is redundant:

KEYEVENTF_EXTENDEDKEY | 0

you can simply make it

KEYEVENTF_EXTENDEDKEY

And this is exactly why I thought it.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Ok, I guess I just don't care enough. I knew what the operation was doing. It looks at the bits rather than the evaluation of the expression. In my mind that is comparing bits. My bad.



And this is exactly why I thought it.

Programming is one discipline where it is considered a virtue to be nitpicky about details and language :).
 

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
Programming is one discipline where it is considered a virtue to be nitpicky about details and language :).

Syntax sure. But I equate this to a grammar nazi.

I've never had to use this in any of my professional work. Maybe if it was more prominent in regards to tasks performed, I'd care more lol.

I did VBA for years, I can't even think of how you'd do a | operation in that language. I only know of it due to C++ in college years ago... It's a good way to figure out if a number is a power of 2.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Syntax sure. But I equate this to a grammar nazi.

I've never had to use this in any of my professional work. Maybe if it was more prominent in regards to tasks performed, I'd care more lol.

I did VBA for years, I can't even think of how you'd do a | operation in that language. I only know of it due to C++ in college years ago... It's a good way to figure out if a number is a power of 2.

Well, I disagree with you there. Programming is a precise business. It's ok not to know about something. If you haven't had to use bitwise logical operators often (and I agree, it doesn't come up very frequently in most modern development) then you wouldn't necessarily know how to talk about them. I had to explain to one of our senior devs a few years back what a bitmask was. But it's not being a "grammar nazi" to insist on the right language once the topic does come up for discussion.

Anyway, programmers are pricks about this stuff, as everyone knows :).
 

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
Well, I disagree with you there. Programming is a precise business. It's ok not to know about something. If you haven't had to use bitwise logical operators often (and I agree, it doesn't come up very frequently in most modern development) then you wouldn't necessarily know how to talk about them. I had to explain to one of our senior devs a few years back what a bitmask was. But it's not being a "grammar nazi" to insist on the right language once the topic does come up for discussion.

Anyway, programmers are pricks about this stuff, as everyone knows :).

But in this event I understood what the operation was doing, just used bad wording to describe it.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
But in this event I understood what the operation was doing, just used bad wording to describe it.

Honestly, if I was interviewing you and this question came up, and these were your responses and attitude, I would quickly show you the door.

Human language is imprecise, but programming is very precise. When talking about programming related subjects you have to be exact in your language or the wrong idea will be conveyed.

Imagine you were tasked with documenting an algorithm so that I could implement it in another language. If you said 'perform a bitwise comparison on the two flag values' I would have no idea what you meant. Compare them how? Is one greater than the other? Are they the same?
 

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
Honestly, if I was interviewing you and this question came up, and these were your responses and attitude, I would quickly show you the door.

Human language is imprecise, but programming is very precise. When talking about programming related subjects you have to be exact in your language or the wrong idea will be conveyed.

Imagine you were tasked with documenting an algorithm so that I could implement it in another language. If you said 'perform a bitwise comparison on the two flag values' I would have no idea what you meant. Compare them how? Is one greater than the other? Are they the same?

If you were interviewing me and this question came up, I'd wonder what you'd have me doing that I'd need to know this. You can judge all you want but this is a forum where I can say what I want without any real reproach. If you want to make a big deal out of it, that's your prerogative and actually highlights an arrogance I'd rather avoid when interviewing someone myself (since you took it there). To each their own, though.

If I was documenting the algorithm I'd show exactly what it was doing using examples. Also I'd care a lot more at that point. This is a public forum, get over yourself already. No one is applying for a job here, and you don't decide whether or not I get the job.
 

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
Of course, and that privilege runs both ways :).

Of course. I already stated it was incorrect / bad wording several posts ago. The arrogance has shifted since then. You guys really have to be trying to get it to this point.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Of course. I already stated it was incorrect / bad wording several posts ago. The arrogance has shifted since then. You guys really have to be trying to get it to this point.

That's an interesting perspective that I don't feel is supported by a reading of the thread, but in any case, as you suggest, hardly worth debating.
 

MrScott81

Golden Member
Aug 31, 2001
1,891
0
76
That's an interesting perspective that I don't feel is supported by a reading of the thread, but in any case, as you suggest, hardly worth debating.

Neither do I, FWIW (which is probably very little).

Bit comparison is a VERY different thing than a bitwise operator. Comparing that to a grammar nazi is not even close to the same thing.
 

Jaydip

Diamond Member
Mar 29, 2010
3,691
21
81
Actually I believe this forum is a refreshing change for me from VCG :)
 

Tweak155

Lifer
Sep 23, 2003
11,449
264
126
Neither do I, FWIW (which is probably very little).

Bit comparison is a VERY different thing than a bitwise operator. Comparing that to a grammar nazi is not even close to the same thing.

We use grammar every day, how often is a bitwise operator used and by how many people? It is a miniscule fraction when comparing the two. Thus, to me, if you have to keep dragging the point on even after I said I used incorrect wording, it is grammar nazi like. I never stated it as fact, it is very much worded as an opinion.

I think the real motivating factor would land on the side of arrogance or some other such similar word. I think arrogance fits the description but there is a better word suited to what I'm looking for, I just can't think of it right now.