win32api GetKeyState loop problem

This is the place for queries that don't fit in any of the other categories.

win32api GetKeyState loop problem

Postby vrkiller » Thu Jul 04, 2013 12:07 pm

I have this code and it work like it should:

Code: Select all
import win32api


VK_CODE=('backspace','tab','clear','enter','shift','ctrl','alt','pause','caps_lock','esc','spacebar','page_up','page_down','end','home','left_arrow','up_arrow','right_arrow',
'down_arrow','select','print','execute','print_screen','ins','del','help','0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p',
'q','r','s','t','u','v','w','x','y','z','numpad_0','numpad_1','numpad_2','numpad_3','numpad_4','numpad_5','numpad_6','numpad_7','numpad_8','numpad_9','multiply_key',
'add_key','separator_key','subtract_key','decimal_key','divide_key','F1','F2','F3','F4','F5','F6','F7','F8','F9','F10','F11','F12','F13','F14','F15','F16''F17','F18','F19','F20',
'F21','F22','F23','F24','num_lock','scroll_lock','left_shift','right_shift','left_control','right_control','left_menu','right_menu','browser_back','browser_forward','browser_refresh',
'browser_stop','browser_search','browser_favorites','browser_start_and_home','volume_mute','volume_Down','volume_up',
'next_track','previous_track','stop_media','play/pause_media','start_mail','select_media','start_application_1','start_application_2','attn_key','crsel_key','exsel_key',
'play_key','zoom_key','clear_key','+',',','-','.','/','`',';','[','\\',']',"'",'`')

Virtual_Key_Codes=[0x08,0x09,0x0C,0x0D,0x10,0x11,0x12,0x13,0x14,0x1B,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,0x36,
0x37,0x38,0x39,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,
0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x90,0x91,0xA0,0xA1,0xA2,
0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xF6,0xF7,0xF8,0xFA,0xFB,0xFE,0xBB,0xBC,0xBD,0xBE,0xBF,0xC0,0xBA,0xDB,0xDC,0xDD,
0xDE,0xC0]



x=0
key=0
a=0
while True:
    if win32api.GetKeyState(Virtual_Key_Codes[x])!=a:
        print(key)
    a=win32api.GetKeyState(Virtual_Key_Codes[x])



But every time i make a loop to tjeck all the Virtual_Key_Codes it dosen't work at all. I don't get it )=
- VrKiller
User avatar
vrkiller
 
Posts: 12
Joined: Fri Jun 28, 2013 10:50 am
Location: Denmark, århus

Re: win32api GetKeyState loop problem

Postby vrkiller » Thu Jul 04, 2013 1:47 pm

I have figured it out now. but every time i run the code and press "f" forexample it print's "ff" and i have no idea why it do that every time? Any help

Code: Select all
VK_CODE=('backspace','tab','clear','enter','shift','ctrl','alt','pause','caps_lock','esc','spacebar','page_up','page_down','end','home','left_arrow','up_arrow','right_arrow',
'down_arrow','select','print','execute','print_screen','ins','del','help','0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p',
'q','r','s','t','u','v','w','x','y','z','numpad_0','numpad_1','numpad_2','numpad_3','numpad_4','numpad_5','numpad_6','numpad_7','numpad_8','numpad_9','multiply_key',
'add_key','separator_key','subtract_key','decimal_key','divide_key','F1','F2','F3','F4','F5','F6','F7','F8','F9','F10','F11','F12','F13','F14','F15','F16''F17','F18','F19','F20',
'F21','F22','F23','F24','num_lock','scroll_lock','left_shift','right_shift','left_control','right_control','left_menu','right_menu','browser_back','browser_forward','browser_refresh',
'browser_stop','browser_search','browser_favorites','browser_start_and_home','volume_mute','volume_Down','volume_up',
'next_track','previous_track','stop_media','play/pause_media','start_mail','select_media','start_application_1','start_application_2','attn_key','crsel_key','exsel_key',
'play_key','zoom_key','clear_key','+',',','-','.','/','`',';','[','\\',']',"'",'`')


Virtual_Key_Codes=[0x08,0x09,0x0C,0x0D,0x10,0x11,0x12,0x13,0x14,0x1B,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35,0x36,
0x37,0x38,0x39,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,
0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x90,0x91,0xA0,0xA1,0xA2,
0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF,0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xF6,0xF7,0xF8,0xFA,0xFB,0xFE,0xBB,0xBC,0xBD,0xBE,0xBF,0xC0,0xBA,0xDB,0xDC,0xDD,
0xDE,0xC0]

import win32api
x=[]
for i in range(0,len(Virtual_Key_Codes)):
    x.append(win32api.GetKeyState(Virtual_Key_Codes[i]))

i=0

while True:
    for key in Virtual_Key_Codes:
        if not win32api.GetKeyState(key)==x[i]:

            print(VK_CODE[i],end=" ")
            x[i]=win32api.GetKeyState(key)
        i+=1
    i=0
- VrKiller
User avatar
vrkiller
 
Posts: 12
Joined: Fri Jun 28, 2013 10:50 am
Location: Denmark, århus


Return to General Coding Help

Who is online

Users browsing this forum: stranac and 4 guests