c++ - How to use GetAsyncKeyState without calling it multiple times? -
this how code looks like:
if (getasynckeystate(vk_control) && getasynckeystate(0x31)) { //... } if (getasynckeystate(vk_control) && getasynckeystate(0x32)) { //... } if (getasynckeystate(vk_control) && getasynckeystate(0x33)) { //... } if (getasynckeystate(vk_control) && getasynckeystate(0x34)) { //... } if (getasynckeystate(vk_control) && getasynckeystate(0x35)) { //... } is there more efficient way of doing without calling getasynckeystate multiple times per loop? maybe store function value integer , use switch statement?
also, not want use registerhotkey.
here tips. 0. calling func slower using value directly. 1. if-else statement can build tree.the tree should optimized path compression. can promote code this.
static bool keys[256]; int getkey(){ //don't forget call before querying "keys" array. for(int i=0;i<256;i++) getasynckeystate(i); return 0; } if(keys[vk_control]) { if (keys[0x31]) { //... } if (keys[0x32]) { //... } if (keys[0x33]) { //... } if (keys[0x34]) { //... } if (keys[0x35]) { //... } }
Comments
Post a Comment