On Win32, How to Detect Whether a Left Shift or Right Alt Is Pressed Using Perl, Python, or Ruby (Or C)

On Win32, how to detect whether a Left Shift or Right ALT is pressed using Perl, Python, or Ruby (or C)?

You need to setup a Low Level Keyboard Hook. You do this by calling SetWindowsHookEx with a LowLevelKeyboardProc, and then watch for the appropriate virtual key code.

There are key codes for left and right shift and alt keys.

How to use Ruby to detect whether on Windows Platform, the SHIFT or ALT key is being pressed?

On Win32, how to detect whether a Left Shift or Right ALT is pressed using Perl, Python, or Ruby (or C)? has some clues...

ruby ffi might help, too

How to handle VK_MENU (alt) keypresses properly using WinAPI?

I can reproduce the problem through code, and then I capture the message of the window through spy++.

We can see that when the ALT key is pressed for the first time, the WM_SYSKEYDOWN and WM_SETTEXT messages are successfully triggered:

Sample Image

When the ALT key is pressed the second time, it actually triggers the WM_SYSKEYDOWN message, but after a series of message sending(WM_CAPTURECHANGED,WM_MENUSELECT...).This resulted in the message not being processed in the main window, but sent to hmenu:00000000, so the main window did not process the WM_SYSKEYDOWN message.

Sample Image

You can handle it by processing the WM_SYSCOMMAND message:

case WM_SYSCOMMAND:
if (wParam == SC_KEYMENU)
{
return 0;
}
else
return DefWindowProc(hwnd, msg, wParam, lParam);
break;

It works for me.

how to write a program in PHP, Ruby, or Python, and make it easily downloadable and installable by general users like a Win32 app?

Ruby

RubyScript2Exe

RubyScript2Exe transforms your Ruby application into a standalone, compressed Windows, Linux or Mac OS X (Darwin) executable.

There's also a decent blog post about it

Another possible option is the Shoes GUI framework, which can create Widows, Linux and OS X executables from your Shoes application.

Python

py2exe

py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.

py2exe is used by BitTorrent, SpamBayes, and thousands more

PHP

Bambalam PHP EXE Compiler/Embedder

Bambalam PHP EXE Compiler/Embedder is a free command line tool to convert PHP applications to standalone Windows .exe applications. The exe files produced are totally standalone, no need for php dlls etc.

and is it possible to make it a Mac app easily too?

Py2App

py2app is a Python setuptools command which will allow you to make standalone application bundles and plugins from Python scripts. py2app is similar in purpose and design to py2exe for Windows.

Also, there is a utility "Build Applet" included with the Developer Tools.. Drag-and-drop a Python script on to it and it becomes a .app. The utility is in /Developer/Applications/Utilities/MacPython 2.5/


Note, all of the above basically take your script, package it up along with a Python interpreter and any dependancies, and on launch run your script. If you use a GUI platform that does not work on Windows, running it through Py2EXE will not make it work!

Also as Peter D mentioned, you need to be careful about dependancies - if your application requires a MySQL database, your users will have to install that separately to use your application, and every library you use will add size to your executables.

Launching a registered mime helper application

Some follow-up to close out this question.

Turned out the real issue was how I was creating the file handle using TFileStream. I changed to open with fmOpenRead or fmShareDenyWrite which solved what turned out to be a file locking issue.

srcFile := TFileStream.Create(physicalFilename, fmOpenRead or fmShareDenyWrite);


Related Topics



Leave a reply



Submit