在没有它们的笔记本电脑上创建 Alt 代码

发布于 2024-12-26 19:10:55 字数 1845 浏览 0 评论 0原文

我的笔记本电脑有一个数字键盘,但没有 NumLock 键,并且数字键盘实际上只是字母上方的一行数字的副本。当我按下这些键时发送的虚拟键代码证实了这一点。

我正在尝试开发一个小程序来模拟按下 alt 键和常规数字时的 alt 代码。我使用低级键盘挂钩(我在另一个程序中使用类似的格式),并首先检查是否按下了任一 alt 键。如果是,我会循环遍历 VK 代码 0x30-0x39(0-9 键)。如果此时按下其中一个键,我会通过返回值 1 来丢弃实际的击键,而是发送该键的小键盘版本(此时 alt 仍被按下)。

我可以确认已到达钩子,并且按下的 alt 键已被成功识别。然而,当我检查 0-9 上的匹配项时,要么只打印了几个,然后再没有匹配项,要么每次按数字时我都必须抬起并按下 alt 键。此外,在按下一个数字后释放 alt,然后按住 alt 并按下另一个数字(此为 16 次)后,一个数字可能会打印 16 次。

另外,我可以通过复制钩子中的部分、将其放入主函数并将 i 替换为 0x30 来确认 SendInput 序列是否有效。运行时,将在文本文档中键入 0。

在文本文档中按住 ALT(下)+6+5+ALT(上)时,会显示“65”。如果我再添加一个 ALT(向下)+6,则会出现 16 个六。

挂钩程序:

LRESULT CALLBACK proc (int code, WPARAM wParam, LPARAM event) //hook proc
{
    if (code < HC_ACTION) //don't process if not meant to
        return CallNextHookEx (0, code, wParam, event); 

    if (GetAsyncKeyState (VK_MENU) & 0x8000) //if either alt is down
    {
        for (int i = 0x30; i <= 0x39; ++i) //loop 0-9
        {
            if (GetAsyncKeyState (i) & 0x8000) //if index is down
            {
                cout << "MATCH\n"; //debug

                input.ki.wVk = i + 0x30; //set VK code to numpad version of index
                input.ki.dwFlags = 0; //key is being pressed
                SendInput (1, &input, sizeof (INPUT)); //send keystroke down

                input.ki.dwFlags = KEYEVENTF_KEYUP; //key is being released
                SendInput (1, &input, sizeof (INPUT)); //send keystroke up

                while (GetAsyncKeyState (i) & 0x8000) //wait for normal key to be released
                    Sleep (10); //don't hog CPU

                return 1; //discard normal key
            } //end if match
        } //end for
    } //end if alt

    return CallNextHookEx (0, code, wParam, event); //if any key not handled, pass on
} //end function

My laptop has a number pad, but it does not have a NumLock key, and the numpad is actually just a copy of the row of numbers above the letters. This is confirmed by the virtual key codes sent when I press these keys.

I'm trying to develop a small program to mimic alt codes when the alt key and regular numbers are pressed. I use a low-level keyboard hook (I have a similar format working in another program), and first check to see if either alt key is down. If either is, I loop through the VK codes 0x30-0x39 (0-9 keys). If one of those is pressed down at that moment, I discard the actual keystroke by returning a value of 1, and instead send a numpad version of that key instead (alt is still pressed down at this time).

I can confirm that the hook is being reached, and that the alt key being down is being recognized successfully. However, when I check for matches on 0-9, either only a couple are printed before nothing matches after that, or I have to lift up and press down the alt key every time I press a number. Additionally, one number may be printed 16 times after releasing alt having pressed a number, and then holding down alt and pressing another (this one is 16x).

Also, I can confirm the SendInput sequence works via copying the part from the hook, putting it into the main function and replacing i with 0x30. Upon running, a 0 will be typed onto the text document.

When holding down ALT(down)+6+5+ALT(up) in a text document, "65" is what shows. If I add another ALT(down)+6, 16 sixes appear.

Hook Procedure:

LRESULT CALLBACK proc (int code, WPARAM wParam, LPARAM event) //hook proc
{
    if (code < HC_ACTION) //don't process if not meant to
        return CallNextHookEx (0, code, wParam, event); 

    if (GetAsyncKeyState (VK_MENU) & 0x8000) //if either alt is down
    {
        for (int i = 0x30; i <= 0x39; ++i) //loop 0-9
        {
            if (GetAsyncKeyState (i) & 0x8000) //if index is down
            {
                cout << "MATCH\n"; //debug

                input.ki.wVk = i + 0x30; //set VK code to numpad version of index
                input.ki.dwFlags = 0; //key is being pressed
                SendInput (1, &input, sizeof (INPUT)); //send keystroke down

                input.ki.dwFlags = KEYEVENTF_KEYUP; //key is being released
                SendInput (1, &input, sizeof (INPUT)); //send keystroke up

                while (GetAsyncKeyState (i) & 0x8000) //wait for normal key to be released
                    Sleep (10); //don't hog CPU

                return 1; //discard normal key
            } //end if match
        } //end for
    } //end if alt

    return CallNextHookEx (0, code, wParam, event); //if any key not handled, pass on
} //end function

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬心 2025-01-02 19:10:55

好吧,我终于回到了这个问题,经过一些更多的测试,我发现以编程方式发送 [ALT ] [num6] [num5] [ALT ] 没有任何作用。我觉得这很奇怪,因为我能够模拟 Mac 键盘上的音量控制键,尽管没有这些键。

由于计算机根本无法发送替代代码,因此我宣布这个有用的工具完全搞砸了,除非我映射数千个字符。

编辑:

要使数字键盘在 G74SX-XA1 上工作,您需要执行以下操作:

  1. 下载 BIOS 203(我不知道 202 是否有效,我从 201 转到 203)。
  2. 将文件放在 FAT32 格式的闪存驱动器上。
  3. 重新启动计算机,然后按 F4 直接进入 EasyFlash,或通过 BIOS 导航到它。自带的Winflash程序无法运行。
  4. 选择闪存驱动器上更新的 BIOS 文件。
  5. 现在数字锁定灯将始终亮起,并且数字键盘将具有数字键盘的虚拟键代码,而不是字母上方的数字。这自然包括 ALT 代码的工作。

Well, I finally came back to this and after some more testing I discovered that programmatically sending [ALT ] [num6] [num5] [ALT ] does nothing whatsoever. I find this odd because I am able to simulate the volume control keys on the Mac keyboards despite not having those keys.

Since the computer simply can't send alt codes, I declare this helpful tool royally screwed unless I map thousands of characters.

EDIT:

Here's what you need to do to get the number pad working on the G74SX-XA1:

  1. Download the BIOS 203 (I don't know if 202 works or not, I went from 201 to 203).
  2. Put the file on a FAT32-formatted flash drive.
  3. Restart the computer and either press F4 to go right into EasyFlash, or navigate to it through the BIOS. The Winflash program that comes with it doesn't work.
  4. Select the updated BIOS file on the flash drive.
  5. Now the numlock light will always be on and the number pad will have the virtual key codes of a number pad, not the numbers above the letters. This naturally includes ALT codes working.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文