Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6326213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:02:49+00:00 2026-05-24T17:02:49+00:00

I am writing a macro recorder (based on PyHook) and cannot make it to

  • 0

I am writing a macro recorder (based on PyHook) and cannot make it to press key combination #2 after it hooked key combination #1, if #1 contains the Alt key. What else should I do besides unpressing modifier keys? (alt, ctrl, shift)? Below are two main functions.

def press_key(Key, gModifiers = []):
    keybd_event(KeyDict["alt"], 0, KEYEVENTF_KEYUP, 0)
    keybd_event(KeyDict["ctrl"], 0, KEYEVENTF_KEYUP, 0)
    keybd_event(KeyDict["shift"], 0, KEYEVENTF_KEYUP, 0)
    for Modifier in gModifiers:
        keybd_event(KeyDict[Modifier], 0, 0, 0)
    keybd_event(KeyDict[Key], 0, 0, 0)
    keybd_event(KeyDict[Key], 0, KEYEVENTF_KEYUP, 0)
    for Modifier in reversed(gModifiers):
        keybd_event(KeyDict[Modifier], 0, KEYEVENTF_KEYUP, 0)

def OnKeyboardEvent(Event):
    global HM, Mode, PressedKeys, PrevKeyName
    if Mode == "play":
        return True
    PyHookKeyName = Event.Key
    IsAppend = 1
    if PyHookKeyName in PyHookDict:
        KeyName = PyHookDict[PyHookKeyName]
        if is_modifier(KeyName) and KeyName == PrevKeyName:
            IsAppend = 0
    elif len(PyHookKeyName) > 1 and PyHookKeyName[0] == "F": # F1 .. F12
        KeyName = PyHookKeyName
    else:
        KeyName = Event.Key
    if Mode == "record" and IsAppend:
        append(PressedKeys, KeyName)
    if not is_modifier(PrevKeyName):
        AppsPressed = 0
        WinPressed = 0
    if KeyName == "apps":
        AppsPressed = 1
    elif KeyName == "win":
        WinPressed = 1
    if Mode == "hook" and KeyName in MacrosKeysDict:
        Mode = "play"
        PressedModifiersSum = pressed_modifiers_sum()
        if PressedModifiersSum in MacrosKeysDict[KeyName]:
            MacroBlock = MacrosDict[(KeyName, PressedModifiersSum)]
            Events = MacroBlock[2]
            for Event in Events:
                press_key(Event[0], Event[1])
        Mode = "hook"
    PrevKeyName = KeyName
    # return True to pass the event to other handlers
    return True
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:02:51+00:00Added an answer on May 24, 2026 at 5:02 pm

    Changing code fragment from

    keybd_event(KeyDict["alt"], 0, KEYEVENTF_KEYUP, 0)
    keybd_event(KeyDict["ctrl"], 0, KEYEVENTF_KEYUP, 0)
    keybd_event(KeyDict["shift"], 0, KEYEVENTF_KEYUP, 0)
    

    to

    keybd_event(KeyDict["ctrl"], 0, KEYEVENTF_KEYUP, 0)
    keybd_event(KeyDict["shift"], 0, KEYEVENTF_KEYUP, 0)
    keybd_event(KeyDict["alt"], 0, KEYEVENTF_KEYUP, 0)
    

    solves the problem. It’s the worst sort of magic that I have ever seen!!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an utility macro which involves checking whether a comma-separated list list contains
I want to make a helper macro for writing match-extensions. I have something like
I am writing a macro for Visual studio that will generate some code. I
I have started writing a Macro in Visual Studio 2005 like this: Public Sub
I'm writing a macro to let me replace the spaces in a string in
I am writing a macro in Excel where I need to get a substring
I am writing a macro in MS Word which should find all highlighted text
I'm writing a Word/VBA macro for a document template. Every time a user saves/creates
I'm writing a Win32 service in C++. I have a custom Assert macro that
I'm writing a macro, but because I'm working for first time in vb, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.