VMware Fusion 2下Windows XP虚拟机小键盘映射问题与Delphi识别需求
Hey there, let's break down your two questions and tackle them step by step—since you're working with the older VMware Fusion 2 + Windows XP setup, some of these fixes are specific to that environment, but they should get you sorted.
You’re right to suspect a keyboard mapping mismatch between VMware Fusion 2 and Windows XP’s expected VK_Key codes. Here’s how you can manually adjust this:
Edit the VMware keyboard mapping file
Fusion 2 stores keyboard layout files in/Library/Application Support/VMware Fusion/keyboards/(on your Mac host) or inside your virtual machine’s.vmwarevmpackage (right-click the VM > Show Package Contents). Look for the layout file matching your keyboard (e.g.,us.vmkeymap).
Open it in a text editor, find the entries for numpad keys, and update their values to match Windows XP’s VK codes. For example:- Numpad 0 should map to
VK_NUMPAD0(hex0x60, decimal 96) - Numpad 1 →
VK_NUMPAD1(0x61, 97) - Continue this pattern up to Numpad 9 (0x69, 105)
Always back up the original file before making changes!
- Numpad 0 should map to
Override mappings in the VM’s .vmx config
If the global keymap file doesn’t work, you can add custom rules directly to your VM’s.vmxfile (found in the.vmwarevmpackage). Add lines like this for each numpad key:key.numpad0 = "keycode 96" key.numpad1 = "keycode 97"Save the file, restart the VM, and test the numpad in your apps again.
Verify with a quick test program
Write a tiny Delphi app to logonkeydownVK codes to confirm the fix. For example:procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin Memo1.Lines.Add(Format('VK Code: %d (0x%.2x)', [Key, Key])); end;This will show you exactly which code is being triggered, so you can tweak mappings until they match Windows’ expected values.
There are a few reliable ways to check for VMware virtualization in Delphi, tailored for Windows XP:
Check VMware-specific registry keys
VMware Tools (which you should have installed for better integration) adds a registry entry that’s easy to detect. Use this function:function IsRunningInVMware: Boolean; var Reg: TRegistry; begin Result := False; Reg := TRegistry.Create; try Reg.RootKey := HKEY_LOCAL_MACHINE; if Reg.OpenKeyReadOnly('SOFTWARE\VMware, Inc.\VMware Tools') then begin Result := True; Reg.CloseKey; end; finally Reg.Free; end; end;Check for the VMware Tools process
If VMware Tools is running, thevmtoolsd.exeprocess will be active. You can scan for it with this code:uses tlhelp32; function IsVMwareToolsActive: Boolean; var hSnapshot: THandle; pe32: TProcessEntry32; begin Result := False; hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if hSnapshot <> INVALID_HANDLE_VALUE then begin pe32.dwSize := SizeOf(TProcessEntry32); if Process32First(hSnapshot, pe32) then begin repeat if SameText(pe32.szExeFile, 'vmtoolsd.exe') then begin Result := True; Break; end; until not Process32Next(hSnapshot, pe32); end; CloseHandle(hSnapshot); end; end;Bonus: Check virtual hardware signatures
For a more low-level check, you can query Windows’ hardware info for VMware-specific identifiers (like "VMware Virtual Disk" or "VMware Ethernet Adapter"). This requires using Windows Setup API functions, but the registry/process methods are simpler and work perfectly for Fusion 2 + XP.
内容的提问来源于stack exchange,提问作者Christian Martin

