If a Key Is Pressed Do This


I have a few things running on a macro but at the end I want the feature "if return is pressed do this and this and this":

I have the below set but for some reason it wont work on pressing it rather it will only work if it's not pressed.

I tried to mess with the "otherwise" part but that doesn't seem to reverse it.

It's nice of you to post your macro, but I had to retype it, and I didn't get your problem when I retyped it. It ran when the key was down.

You can remove stuff from your macro that you don't want us to see (that helps us) but if you post the actual macro we can run it and give you better assistance.

P.S. Are you aware of the different between RETURN and ENTER?

P.S. I'm off to get some breakfast.

so let me give you a little colour. Basically when im in excel i have excel and firefox split screen next to each other.
For my spreadsheet i often need a number on firefox page and then paste it to excel. i then just made a shortcut that would open firefox, copy number, paste in excel and then switch tabs and do the process over again. However when i type "return" when im done adding up all the numbers i want it to go to next column and type words in. everything works perfectly till that point. even if i put this shortcut in a fresh macro i still cant get it to work in excel. weird

anyways, hope you enjoy brekkie and below is the shortcut
shortcut 1.kmmacros (9.4 KB)

Well, I'm just an average guy here, without Excel, or Firefox, so I can't really test it, but I've looked at your macro. I'm a little confused why you would want to check if "the RETURN key is pressed". The way you've written it, it will execute that branch only if you have the RETURN key pressed at the exact moment that that statement executes. This means your macro is highly dependent on timing, and I probably wouldn't be able to time my pressing of the RETURN key if I was running this macro.

In my opinion what you want is a second macro that triggers, actually triggers, on the pressing of the RETURN key. What you are doing here is "polling" the key, and if the key isn't pressed at the exact microsecond that that statement runs, it will fail to detect it, which is what you are seeing.

As you said, "when i type "return" ... i want it to go to next column and type words in" and that means you want a trigger that starts something when the return key is pressed. So I think the problem is that you are trying to poll the key instead of taking an action WHEN the key is pressed.

I'm usually right 80% of the time, but this week I'm running only about 60%, so I could be wrong here.

you are 100% correct so what am i doing wrong here. I feel like im def using the wrong function and its a lack of brain power on my end

No worry.

What I think you need is two macros. The first one is the one you already have, but the IF statement at the bottom needs to be removed and placed into a second macro that has a trigger that occurs when you press the RETURN key.

They are completely independent actions and merit their own independent triggers.

But bear in mind that I'm just doing my best here, and I'm not always right.

made a second macro to do this and still not working its really weird. if its on "up" not "down" it works

I think the reason it's not working is because you aren't using a trigger. You are "polling" to see if the key is down. That's not what you need to do when you want an action to run WHEN you press a key.

You use a "trigger when hotkey is pressed" trigger, and then you just assume that the ENTER key is pressed. You NEVER check to see if it's pressed with an IF statement.

I'm 80% sure that this is your problem. I assumed you knew how to write macros using triggers because the first macro you uploaded correctly uses a trigger.

Do you need me to write the second macro for you? Perhaps I could see what you are doing wrong if you uploaded your second macro rather than send a screenshots. The problem with screenshots is that they don't show the trigger, and your problem seems to be with the trigger.

yeah if i made it with a trigger it would occur every single time i pressed enter and i only want it to happen should i press enter after that specific macro runs

Okay. This is tricky (but not impossible) because your requirement is now ambiguous. For example, how long after the first macro do you want the ENTER key to trigger the second macro? Is there a 1-second limit? A 60-second limit? A 24-hour limit? What you are asking for now is no longer a trigger. A trigger occurs WHEN something happens, but not you are asking for a trigger that occurs depending on a series of conditions. One of those conditions is when the first macro runs. Another condition is a time limit which you haven't specified. Another condition is whether other keys that might be pressed before the RETURN key is pressed will make the RETURN key fail to work. Do you want me to guess what you want for all these questions, or do you want to tell me what you want for all these conditions? If I guessed, I might end up writing a macro for you that doesn't do what you want.

And besides all this, I don't see why you "only want it to happen should i press enter after that specific macro runs"? This requirement doesn't make sense to me because you can just disable the macro when you no longer want it to work. Disabling a macro is very simple, but programming a macro to handle a long series of conditions can be very complicated. Why do you not want the simple solution?

i just stepped out for fresh air and had a brainstorm. I will just type the words in the next column before my first macro starts that way it doesnt need to watch for the enter key to be hit. im really dumb and sorry for wasting your time. LEGEND THO

I enjoy helping people. It's not a waste of my time. I only ask that you tolerate my limitations and occasional failings. You aren't dumb. Only a smart person could use KM. And I myself use less than 50% of it.

best app i ever did lay my eyes on

Agreed. It's worthy (maybe even overqualified) of being an Apple product. However I can see Apple's direction is to make apps that work on all its OSs, including tablets, phones, TVs, HomePods, Glasses, etc., and KM seems to be a macOS only product, so I don't think Apple would want it to be their own.