Sunday, April 3, 2016

How to enable tab and arrow keys using python win32gui

Leave a Comment

I've created several buttons (windows) in a main window, but tab and arrow keys are not working. My research revealed that for C++, the use of IsDialogMessage in the message pump creates a bypass of TranslateMessage/DispatchMessage as follows to allow this functionality:

while(GetMessage(&Msg, NULL, 0, 0)) {     if(!IsDialogMessage(g_hToolbar, &Msg))     {         TranslateMessage(&Msg);         DispatchMessage(&Msg);     } } 

However, I'm using python and the win32gui module to CreateWindows and I can't figure out how to bypass the normal message capture to allow natural handling of the keyboard. My code is similar to this:

hwnd = CreateWindow(classAtom, "", win32con.WS_OVERLAPPED | win32con.WS_CAPTION |                      win32con.WS_SYSMENU | win32con.WS_MINIMIZEBOX | win32con.WS_EX_TOPMOST |                      win32con.WS_CLIPSIBLINGS, x, y, width, height, 0,  0,                      GetModuleHandle(None), None) btn1_hwnd = CreateWindow("Button", "btn 1", win32con.WS_GROUP | win32con.WS_TABSTOP |                           win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.BS_DEFPUSHBUTTON |                           win32con.WS_CLIPSIBLINGS, x, y, width, height, hwnd, 0,                           GetModuleHandle(None), None) btn2_hwnd = CreateWindow("Button", "btn 2", win32con.WS_GROUP |                           win32con.WS_TABSTOP | win32con.WS_VISIBLE | win32con.WS_CHILD |                            win32con.BS_DEFPUSHBUTTON | win32con.WS_CLIPSIBLINGS, x, y,                            width, height, hwnd, 0, GetModuleHandle(None), None) 

1 Answers

Answers 1

There are two answers, short and long.

Short answer, just install keyboard v0.6.5.

Long answer: grok the keyboard short code, then install it.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment