def get_layout_spec(self): layout = None layouts = [] variant = None variants = None try: l = win32api.GetKeyboardLayoutList() log("win32api.GetKeyboardLayoutList()=%s", csv(hex(v) for v in l)) for hkl in l: kbid = hkl & 0xffff if kbid in WIN32_LAYOUTS: code, _, _, _, _layout, _variants = WIN32_LAYOUTS.get(kbid) log( "found keyboard layout '%s' with variants=%s, code '%s' for kbid=%i (%#x)", _layout, _variants, code, kbid, hkl) if _layout not in layouts: layouts.append(_layout) except Exception as e: log.error("Error: failed to detect keyboard layouts: %s", e) try: hkl = win32api.GetKeyboardLayout(0) log("win32api.GetKeyboardLayout(0)=%#x", hkl) kbid = hkl & 0xffff if kbid in WIN32_LAYOUTS: code, _, _, _, layout, variants = WIN32_LAYOUTS.get(kbid) log( "found keyboard layout '%s' with variants=%s, code '%s' for kbid=%i (%#x)", layout, variants, code, kbid, hkl) if not layout: log("unknown keyboard layout for kbid: %i (%#x)", kbid, hkl) else: layouts.append(layout) except Exception as e: log.error("Error: failed to detect keyboard layout: %s", e) return layout, layouts, variant, variants
def set_keyboard_layout(): w = win32gui window_title = w.GetWindowText(w.GetForegroundWindow()) print(window_title) if 'whatsapp' in window_title.lower(): py_win_keyboard_layout.change_foreground_window_keyboard_layout( -264436723) # to switch to Heb print("Keyboard changed" + str(win32api.GetKeyboardLayout())) elif 'visual studio code' in window_title.lower(): py_win_keyboard_layout.change_foreground_window_keyboard_layout( 67699721) # to switch to Heb print("Keyboard changed" + str(win32api.GetKeyboardLayout())) elif 'chrome' in window_title.lower(): py_win_keyboard_layout.change_foreground_window_keyboard_layout( 67699721) # to switch to Heb print("Keyboard changed" + str(win32api.GetKeyboardLayout()))
def wrapper(*args, **kwargs): if win32api.LoadKeyboardLayout('0x0409', win32con.KLF_ACTIVATE) == None: return Exception('加载键盘失败') # 语言代码 # https://msdn.microsoft.com/en-us/library/cc233982.aspx LID = { 0x0804: "Chinese (Simplified) (People's Republic of China)", 0x0409: 'English (United States)' } # 获取前景窗口句柄 hwnd = win32gui.GetForegroundWindow() # 获取前景窗口标题 title = win32gui.GetWindowText(hwnd) # 获取键盘布局列表 im_list = win32api.GetKeyboardLayoutList() im_list = list(map(hex, im_list)) print(im_list) oldKey = hex(win32api.GetKeyboardLayout()) # 设置键盘布局为英文 result = win32api.SendMessage(hwnd, WM_INPUTLANGCHANGEREQUEST, 0, 0x4090409) if result == 0: print('设置英文键盘成功!') inner(*args, *kwargs) result = win32api.SendMessage(hwnd, WM_INPUTLANGCHANGEREQUEST, 0, oldKey) if result == 0: print('还原键盘成功!')
def keycode_from_key(self, key): if key in self.replacement_mods: return self.replacement_mods[key] if key in self.replacement_keys: return self.replacement_keys[key] if len(key) == 1: return win32api.VkKeyScanEx(key, win32api.GetKeyboardLayout())
def get_current_layout(): """ Get the foreground window's current keyboard layout. :rtype: int :returns: current keyboard layout (HKL DWORD) """ thread_id = win32process.GetWindowThreadProcessId( win32gui.GetForegroundWindow())[0] # Return the HKL as a 32-bit unsigned integer. return win32api.GetKeyboardLayout(thread_id) & 0xffffffff
def btn_add_plateg(self): self.win_add = UiWinAdd() self.win_add.name_plateg() if win32api.GetKeyboardLayout() == 67699721: # 67699721 - английский 00000409 win32api.LoadKeyboardLayout("00000419", 1) # 68748313 - русский 00000419 # КНОПКИ окна ДОБАВЛЕНИЕ ПЛАТЕЖА self.win_add.btn_OK.clicked.connect(self.win_add_name_ok) # кнопка OK окна ИМЯ self.win_add.btn_OK.setAutoDefault(True) self.win_add.lineEdit.returnPressed.connect(self.win_add.btn_OK.click) self.win_add.btn_Cancel.clicked.connect(self.win_add_name_cancel) # кнопка CANCEL
def get_layout_spec(self): layout = None variant = None variants = None try: import win32api #@UnresolvedImport kbid = win32api.GetKeyboardLayout(0) & 0xffff if kbid in WIN32_LAYOUTS: code, _, _, _, layout, variants = WIN32_LAYOUTS.get(kbid) log("found keyboard layout '%s' with variants=%s, code '%s' for kbid=%s", layout, variants, code, kbid) if not layout: log("unknown keyboard layout for kbid: %s", kbid) except Exception, e: log.error("failed to detect keyboard layout: %s", e)
def win_add_name_ok(self): self.name = self.win_add.lineEdit.text() self.win_add.lineEdit.clear() self.win_add.close() self.summ_plat = UiWinAdd() self.summ_plat.name_plateg() self.summ_plat.label.setText("Сумма платежа") if win32api.GetKeyboardLayout() == 68748313: # 67699721 - английский 00000409 win32api.LoadKeyboardLayout("00000409", 1) # 68748313 - русский 00000419 self.summ_plat.btn_OK.clicked.connect(self.win_add_summ_ok) # кнопка OK окна СУММА self.summ_plat.btn_OK.setAutoDefault(True) self.summ_plat.lineEdit.returnPressed.connect(self.summ_plat.btn_OK.click) self.summ_plat.btn_Cancel.clicked.connect(self.win_add_summ_cancel)
def collecting_computer_information(): user = "******" + win_api.GetUserName() computer_name = "Имя компьютера: " + win_api.GetComputerName() windows_directory = "Путь к папке OS Windows: " + win_api.GetWindowsDirectory( ) system_directory = "Путь к папке с системными файлами: " + win_api.GetSystemDirectory( ) volume_label = "Метка Тома: " + str(win_api.GetVolumeInformation("E:\\")) memory = "Обьем Памяти:" + str(win_api.GetDiskFreeSpace()) screen_height = "Высота экрана: " + str(win_api.GetSystemMetrics(0)) keyboard_type = "Тип и подтип клавиатуры: " + str( win_api.GetKeyboardLayout()) all_info = " ".join([ user, computer_name, windows_directory, system_directory, volume_label, memory, screen_height, keyboard_type ]) all_info = sha512(all_info.encode()) return all_info.hexdigest()
def get_layout_spec(self): layout = None layouts = [] variant = None variants = None try: kbid = win32api.GetKeyboardLayout(0) & 0xffff if kbid in WIN32_LAYOUTS: code, _, _, _, layout, variants = WIN32_LAYOUTS.get(kbid) log( "found keyboard layout '%s' with variants=%s, code '%s' for kbid=%s", layout, variants, code, kbid) if not layout: log("unknown keyboard layout for kbid: %s", kbid) else: layouts.append(layout) except Exception as e: log.error("failed to detect keyboard layout: %s", e) return layout, layouts, variant, variants
def win_add_name_ok(self): self.radio_plat.close() if win32api.GetKeyboardLayout( ) == 67699721: # 67699721 - английский 00000409 win32api.LoadKeyboardLayout("00000419", 1) # 68748313 - русский 00000419 self.win_add = UiWinAdd() self.win_add.name_plateg() self.name = self.win_add.lineEdit.text() self.win_add.btn_OK.clicked.connect(self.win_add_summ_ok) # кнопка OK self.win_add.btn_OK.setAutoDefault(True) self.win_add.lineEdit.returnPressed.connect(self.win_add.btn_OK.click) self.win_add.btn_Cancel.clicked.connect( self.win_add_name_cancel) # кнопка CANCEL
def set_keyboard_layout(): w = win32gui window_title = w.GetWindowText(w.GetForegroundWindow()) print("Title: " + window_title) if 'whatsapp' in window_title.lower(): py_win_keyboard_layout.change_foreground_window_keyboard_layout( -264436723) # to switch to Heb print("Keyboard changed " + str(win32api.GetKeyboardLayout()) + " Hebrew, whatsapp") elif any("\u0590" <= c <= "\u05EA" for c in window_title): py_win_keyboard_layout.change_foreground_window_keyboard_layout( -264436723) # to switch to Heb print("Keyboard changed " + str(win32api.GetKeyboardLayout()) + " Hebrew, heb") elif 'visual studio code' in window_title.lower(): py_win_keyboard_layout.change_foreground_window_keyboard_layout( 67699721) # to switch to en print("Keyboard changed " + str(win32api.GetKeyboardLayout()) + " English, vsc") elif 'chrome' in window_title.lower(): py_win_keyboard_layout.change_foreground_window_keyboard_layout( 67699721) # to switch to en print("Keyboard changed " + str(win32api.GetKeyboardLayout()) + " English, chrome") elif 'gitkraken' in window_title.lower(): py_win_keyboard_layout.change_foreground_window_keyboard_layout( 67699721) # to switch to en print("Keyboard changed " + str(win32api.GetKeyboardLayout()) + " English, git") elif 'cmd' in window_title.lower(): py_win_keyboard_layout.change_foreground_window_keyboard_layout( 67699721) # to switch to en print("Keyboard changed " + str(win32api.GetKeyboardLayout()) + " English, cmd") elif 'ssh' in window_title.lower(): py_win_keyboard_layout.change_foreground_window_keyboard_layout( 67699721) # to switch to en print("Keyboard changed " + str(win32api.GetKeyboardLayout()) + " English, ssh")
def text_editing(self, lineEdit_sum): try: if win32api.GetKeyboardLayout() == 68748313: # 67699721 - английский 00000409 win32api.LoadKeyboardLayout("00000409", 1) # 68748313 - русский 00000419 self.label_ERROR_KP.clear() self.checkBox_Edit_KP.show() year = self.comboBox_year_KP.currentText() if lineEdit_sum == self.lineEdit_sum_Power: self.sum_platega(self.dict_pole, 'Электричество', year) elif lineEdit_sum == self.lineEdit_sum_Water: self.sum_platega(self.dict_pole, 'Вода', year) elif lineEdit_sum == self.lineEdit_sum_Gaz: self.sum_platega(self.dict_pole, 'Газ', year) elif lineEdit_sum == self.new_p.lineEdit_sum_Plat: v = self.dict_pole.get(self.new_p.label_Plat.text()) pl_sum = float(v.text()) list_pl = pl_sum, 0, 0 self.dop_plategi[self.new_p.label_Plat.text()] = list_pl def ok(): den_ok = denominacia(year, pl_sum) v.setText(den_ok + " руб") v.returnPressed.connect(ok) self.plategi_sum = 0 for i, j in self.dop_plategi.items(): self.plategi_sum += float(j[0]) if type(j) == tuple else float(j) self.itog_sum(self.plategi_sum) except ValueError: self.checkBox_Edit_KP.hide() self.label_ERROR_KP.setText('Должно быдь значение!')
def get_current_layout(cls): # Get the current window's keyboard layout. thread_id = win32process.GetWindowThreadProcessId( win32gui.GetForegroundWindow())[0] return win32api.GetKeyboardLayout(thread_id)
def GetCurrentLocale(): return w3a.GetKeyboardLayout( w3p.GetWindowThreadProcessId(w3g.GetForegroundWindow())[0]) & 0xFFFF
import win32api, win32con, win32gui import time, win32com.client shell = win32com.client.Dispatch("WScript.Shell") if (str(win32api.GetKeyboardLayout()).__eq__('67699721')): print(str(win32api.GetKeyboardLayout())) shell.SendKeys("^+") time.sleep(1) time.sleep(3) shell.SendKeys( "F,jytyncrbq geyrn hfpdthyen yf FHV gjkmpjdfntkz? ghjdtltyj j,extybt hf,jnt c Ltkjdjq gjxnjq? ghjbpdtlty ex`n CRPB? ljrevtyns gthtlfys d JRP" ) # ' Абонентский пункт развернут на АРМ пользователя, проведено обучение работе с Деловой почтой, произведен учёт СКЗИ, документы переданы в ОКЗ.')
def read_pokaz_schet(self): if win32api.GetKeyboardLayout( ) == 68748313: # 67699721 - английский 00000409 win32api.LoadKeyboardLayout("00000409", 1) # 68748313 - русский 00000419 file_db = open('Komunal.db', 'a') # открываем файл базы данных file_db.close() self.data_base = 'Komunal.db' # имя базы данных table = 'Pokazanya_year_' + str( self.comboBox_year_PS.currentText()) # имя таблицы col_name = 'id' # Имя колонки heading = ( 'id integer primary key , month_year text, Pred_PW integer, Actual_PW integer, Pred_WA_1 integer, ' 'Actual_WA_1 integer, Pred_WA_2 integer, Actual_WA_2 integer, Pred_WA_3 integer, ' 'Actual_WA_3 integer, Pred_WA_4 integer, Actual_WA_4 integer, Pred_GZ integer, Actual_GZ integer, ' 'PW_month_ras integer, WA_C_month_ras integer, WA_H_month_ras integer, WA_month_ras integer, ' 'GZ_month_ras integer') # это нужно если база данных отсутствует sqlite3_create_db(self.data_base, table, heading) # создаем таблицу в базе данных # очищаем поля окна ПОКАЗАНИЯ СЧЕТЧИКОВ win_pole = [ self.lineEdit_pred_pokaz_P, self.lineEdit_post_pokaz_P, self.lineEdit_pred_pokaz_W1, self.lineEdit_post_pokaz_W1, self.lineEdit_pred_pokaz_W2, self.lineEdit_post_pokaz_W2, self.lineEdit_pred_pokaz_W3, self.lineEdit_post_pokaz_W3, self.lineEdit_pred_pokaz_W4, self.lineEdit_post_pokaz_W4, self.lineEdit_pred_pokaz_G, self.lineEdit_post_pokaz_G, self.label_month_ras_P, self.label_month_ras_WC, self.label_month_ras_WH, self.label_month_ras, self.label_month_ras_G, self.label_ERROR_PS, self.label_OK_PS ] for i in win_pole: i.clear() self.checkBox_Edit_PS.show() if self.comboBox_month_PS.currentIndex() + 1 in sqlite3_read_db( self.data_base, table, col_name)[0]: self.label_OK_PS.setPixmap( QtGui.QPixmap("./Resource/img/Galochka.png")) if not sqlite3_read_db(self.data_base, table)[0] and month[ self.comboBox_month_PS.currentIndex()] == "Январь": table = 'Pokazanya_year_' + str( int(self.comboBox_year_PS.currentText()) - 1) read_table = sqlite3_read_db(self.data_base, table) # читаем таблицу из базе данных read_table = read_table[0] for i in range(len(read_table)): pred_pokaz = read_table[i] # показания сохраненного периода if self.label_month_year_PS.text() == pred_pokaz[1]: # присваеваем полям значения из сохраненной таблицы for a, b in zip(win_pole[:18], range(2, 19)): a.setText(str(pred_pokaz[b])) break else: cor_month = month[self.comboBox_month_PS.currentIndex() - 1] if cor_month in pred_pokaz[1]: # присваеваем полям "ПРЕДЫДУЩИЕ" значения из сохраненной таблицы for c, d in zip(win_pole[:11:2], range(3, 14, 2)): c.setText(str(pred_pokaz[d])) # присваеваем полям "ПОСЛЕДНЕЕ" и "МЕСЯЧНЫЙ расход" значения "0" for j in win_pole[1:12:2] + win_pole[12:17]: j.setText("0") self.lineEdit_post_pokaz_P.textEdited[str].connect( lambda: self.text_editing(self.label_month_ras_P)) self.lineEdit_pred_pokaz_P.textEdited[str].connect( lambda: self.text_editing(self.label_month_ras_P)) self.lineEdit_post_pokaz_W1.textEdited[str].connect( lambda: self.text_editing(self.label_month_ras_WC)) self.lineEdit_pred_pokaz_W1.textEdited[str].connect( lambda: self.text_editing(self.label_month_ras_WC)) self.lineEdit_post_pokaz_W2.textEdited[str].connect( lambda: self.text_editing(self.label_month_ras_WH)) self.lineEdit_pred_pokaz_W2.textEdited[str].connect( lambda: self.text_editing(self.label_month_ras_WH)) self.lineEdit_post_pokaz_W3.textEdited[str].connect( lambda: self.text_editing(self.label_month_ras_WC)) self.lineEdit_pred_pokaz_W3.textEdited[str].connect( lambda: self.text_editing(self.label_month_ras_WC)) self.lineEdit_post_pokaz_W4.textEdited[str].connect( lambda: self.text_editing(self.label_month_ras_WH)) self.lineEdit_pred_pokaz_W4.textEdited[str].connect( lambda: self.text_editing(self.label_month_ras_WH)) self.lineEdit_post_pokaz_G.textEdited[str].connect( lambda: self.text_editing(self.label_month_ras_G)) self.lineEdit_pred_pokaz_G.textEdited[str].connect( lambda: self.text_editing(self.label_month_ras_G))
def on_click(self): loginName = self.loginTextbox.text() passwOfLogin = self.passTextbox.text() count = int(self.countTextbox.text()) #67699721 en #68748313 rus chromeOptions = webdriver.ChromeOptions() chromeOptions.add_argument('--disable-extensions') chrome = webdriver.Chrome("C:/chromedriver.exe") chrome.maximize_window() chrome.get('https://support.rosatom.ru/sm/index.do') html = chrome.page_source login = chrome.find_element_by_id("username") login.click() login.send_keys("gk\\" + loginName) password = chrome.find_element_by_id("password") password.click() password.send_keys(passwOfLogin) submit = chrome.find_element_by_id("SubmitCreds") submit.click() time.sleep(40) i = 0 if (str(win32api.GetKeyboardLayout()).__eq__('67699721')): chLangMy() i += 1 print(win32api.GetKeyboardLayout()) time.sleep(20) win32api.keybd_event(win32con.VK_SPACE, 0, 0, 0) time.sleep(5) win32api.keybd_event(win32con.VK_TAB, 0, 0, 0) time.sleep(5) for num in range(count): win32api.keybd_event(win32con.VK_RETURN, 0, 0, 0) time.sleep(20) click(609, 215) time.sleep(25) for number in range(9): win32api.keybd_event(win32con.VK_TAB, 0, 0, 0) time.sleep(1) press('3', '0') time.sleep(1) win32api.keybd_event(win32con.VK_RETURN, 0, 0, 0) time.sleep(2) # win32api.keybd_event(win32con.VK_RETURN, 0, 0, 0) time.sleep(2) # for number in range(4): win32api.keybd_event(win32con.VK_TAB, 0, 0, 0) time.sleep(1) #press('c', 't', 'h', 'n', 'b', 'a', 'b', 'r', 'f', 'n', 'spacebar', 'd', 's', 'g', 'e', 'o', 't', 'y', # '/') press('f', ',', 'j', 'y', 't', 'y', 'n', 'c', 'r', 'b', 'q', 'spacebar', 'g', 'e', 'y', 'r', 'n', 'spacebar', 'c', 'j', 'p', 'l', 'f', 'y', '/') for number in range(2): win32api.keybd_event(win32con.VK_TAB, 0, 0, 0) time.sleep(1) press('h', 't', 'i', 't', 'y', 'j') time.sleep(1) win32api.keybd_event(win32con.VK_RETURN, 0, 0, 0) click(733, 215) time.sleep(15) click(382, 215) time.sleep(15) if (i != 0): chLangMy() time.sleep(1020) chrome.quit() QMessageBox.information(self, 'Результат ', 'Обработано ' + str(count) + ' обращений.', QMessageBox.Ok, QMessageBox.Ok)
def on_click(self): shell = win32com.client.Dispatch('WScript.Shell') loginName = self.loginTextbox.text() passwOfLogin = self.passTextbox.text() count = int(self.countTextbox.text()) #67699721 en #68748313 rus chromeOptions = webdriver.ChromeOptions() chromeOptions.add_argument('--disable-extensions') chrome = webdriver.Chrome("C:/chromedriver.exe") chrome.maximize_window() chrome.get('https://support.rosatom.ru/sm/index.do') html = chrome.page_source login = chrome.find_element_by_id("username") login.click() login.send_keys("gk\\" + loginName) password = chrome.find_element_by_id("password") password.click() password.send_keys(passwOfLogin) submit = chrome.find_element_by_id("SubmitCreds") submit.click() time.sleep(40) i = 0 if (str(win32api.GetKeyboardLayout()).__eq__('67699721')): chLangMy() i += 1 print(win32api.GetKeyboardLayout()) time.sleep(20) win32api.keybd_event(win32con.VK_SPACE, 0, 0, 0) time.sleep(5) win32api.keybd_event(win32con.VK_TAB, 0, 0, 0) time.sleep(5) for num in range(count): win32api.keybd_event(win32con.VK_RETURN, 0, 0, 0) time.sleep(20) click(609, 215) time.sleep(25) for number in range(9): win32api.keybd_event(win32con.VK_TAB, 0, 0, 0) time.sleep(1) #press('3', '0') shell.SendKeys('30') time.sleep(1) win32api.keybd_event(win32con.VK_RETURN, 0, 0, 0) time.sleep(2) # win32api.keybd_event(win32con.VK_RETURN, 0, 0, 0) time.sleep(2) for number in range(4): win32api.keybd_event(win32con.VK_TAB, 0, 0, 0) time.sleep(1) #press('c', 't', 'h', 'n', 'b', 'a', 'b', 'r', 'f', 'n', 'spacebar', 'd', 's', 'g', 'e', 'o', 't', 'y', # '/') shell.SendKeys( "F,jytyncrbq geyrn hfpdthyen yf FHV gjkmpjdfntkz? ghjdtltyj j,extybt hf,jnt c Ltkjdjq gjxnjq? ghjbpdtlty ex`n CRPB? ljrevtyns gthtlfys d JRP" ) for number in range(2): win32api.keybd_event(win32con.VK_TAB, 0, 0, 0) time.sleep(1) shell.SendKeys('htityj') time.sleep(1) win32api.keybd_event(win32con.VK_RETURN, 0, 0, 0) click(733, 215) time.sleep(15) click(382, 215) time.sleep(15) if (i != 0): chLangMy() time.sleep(1020) chrome.quit() QMessageBox.information(self, 'Результат ', 'Обработано ' + str(count) + ' обращений.', QMessageBox.Ok, QMessageBox.Ok)