win11 rbr

发布时间 2023-04-03 23:40:41作者: ddd_vimrc

安装Vjoy软件和FreePIE

需要需要把
C:\Program Files\vJoy\x86 目录下的 vJoyInterface.dll 与 vJoyInterfaceWrap.dll
复制到 C:\Program Files (x86)\FreePIE 目录下覆盖同名文件
就是freepie里面和vjoy联动的文件太旧了。

freepie复制下面的脚本并 run script即可。

m_sens = 40.0 # 鼠标灵敏度,数值越大转向越快
m_redu = 2 # 中心缩减,合理数值范围1-50,设置为1时即无中心缩减。

改动这2个即可。

from ctypes import *
user32 = windll.user32 # 调用鼠标锁定功能所需库

if starting:
	# 功能开关,True为开启,False为关闭
	vjoyaxis = True # 转向轴与踏板开关
	mouselock = False # AC鼠标位置锁定(隐藏)专属开关(这里不要修改,后面可以设置开关快捷键)
	# 辅助开关
	autocut = False # 升档自动断油
	autoblip = False # 降档自动补油
	# 映射vJoy设备号
	v = vJoy[0]
	# vjoy最大轴行程,勿改!
	a_max = 4 + v.axisMax
	a_min = -4 - v.axisMax
	# 鼠标转向
	m_sens = 22.0 # 鼠标灵敏度,数值越大转向越快  
	m_redu = 4 # 中心缩减,合理数值范围1-50,设置为1时即无中心缩减。
	steering = 0 # 勿改!
	center_redu = 1 # 勿改!
	# 油门
	th_axis = a_min # 勿改!
	th_inc = 3000 # 油门提升速率,数值越大油门提升越快
	th_dec = 3000 # 松油速率,数值越大松油越快
	th_max = a_max # 控制油门实时行程限制,勿改!
	# 刹车
	br_axis = a_min # 勿改!
	br_inc = 3000 # 刹车提升速率,数值越大油门提升越快
	br_dec = 3000 # 松刹速率,数值越大松刹越快
	br_max = a_max # 控制刹车实时行程限制,勿改!
	# 手刹
	ha_axis = a_min # 勿改!
	ha_inc = 3000
	ha_dec = 3000
	# 离合
	cl_axis = a_min # 勿改!
	cl_inc = 6000
	cl_dec = 6000
	# 自动断油间隔与自动回油速率(仅在踩住油门并升挡时有效)
	cut_rate = 35000 # 自动回油速率,合理数值范围 500 - 10000,设置35000为瞬间回满油
	cut_min = 15 # 最小断油间隔,数值越低断油时间越短
	cut_max = 35000 / cut_rate + cut_min + 4 # 勿改!此公式用于避免自动回油速率与油门速率之间发生冲突
	# 自动补油
	blip_m = 0.6 # 自动补油的油门行程。数值范围 0.0 - 1.0,0.0即无补油,0.5即油门踩一半
	a_blip = a_max * 2 * blip_m - a_max # 勿改!用于计算
	# 油门实时行程限制
	tlimit = 1.0 # 数值范围 0.0 - 1.0,0.9即油门踩90%
	th_limit = a_max * 2 * tlimit - a_max # 勿改!用于计算
	# 换挡计时(用于计算自动断油)
	stimer = 0 # 勿改!
	etimer = cut_max + 100 # 达到最大值后自动终止计时

#======== 键位映射 ========#
# 开关
toggle_mouselock = keyboard.getPressed(Key.End) # AC用鼠标锁定(隐藏)
key_assists_on = keyboard.getPressed(Key.NumberPad1) # 开启自动断油辅助
key_assists_off = keyboard.getPressed(Key.NumberPad3) # 关闭自动断油辅助
# 车辆控制
key_throttle = keyboard.getKeyDown(Key.A) # 油门    
key_brake = keyboard.getKeyDown(Key.S) # 刹车
key_handbrake = keyboard.getKeyDown(Key.Space) # 手刹
key_clutch = keyboard.getKeyDown(Key.W) # 离合
key_centerx = mouse.getButton(2) # 转向回中
key_shiftup =  keyboard.getKeyDown(Key.LeftShift)# 升档
ashift_up_key = mouse.getPressed(0) # 升档计时,同升档键,但使用getPressed状态
key_shiftdown = keyboard.getKeyDown(Key.D)  # 降档
#key_light = keyboard.getKeyDown(Key.L)  # 灯光
# 刹车实时行程限制
bl_70 = keyboard.getPressed(Key.NumberPad7)
bl_75 = keyboard.getPressed(Key.NumberPad4)
bl_80 = keyboard.getPressed(Key.NumberPad8)
bl_85 = keyboard.getPressed(Key.NumberPad5)
bl_90 = keyboard.getPressed(Key.NumberPad9)
bl_95 = keyboard.getPressed(Key.NumberPad6)
no_bl = keyboard.getPressed(Key.NumberPadPeriod)
# 油门实时行程限制
key_throttle_limit = keyboard.getKeyDown(Key.X) # 只有按下此键时才会限制油门行程

#======== 开关(勿改) ========#
if toggle_mouselock:
	mouselock = not mouselock
if key_assists_on: 
	autocut = True
if key_assists_off:
	autocut = False

#======== 转向轴与踏板 ========#
if (vjoyaxis):
	#======== 鼠标锁定 ========#
	if (mouselock):
		user32.SetCursorPos(100 , 5000) # 鼠标在屏幕上的像素坐标(x, y),AC专用
	# 鼠标转向
	if steering > 0:
		center_redu = m_redu ** (1 - (steering / a_max))
	elif steering < 0:
		center_redu = m_redu ** (1 - (steering / a_min))
	steering += (mouse.deltaX * m_sens) / center_redu
	if steering > a_max:
		steering = a_max
	elif steering < a_min:
		steering = a_min
	if key_centerx:
		steering = 0
	# 油门轴
	if key_throttle:
	    th_axis += th_inc
	else:
	    th_axis -= th_dec
	if th_axis > th_max:
	    th_axis = th_max
	elif th_axis < a_min:
	    th_axis = a_min
	# 刹车轴
	if key_brake:
	    br_axis += br_inc
	else:
	    br_axis -= br_dec
	if br_axis > br_max:
	    br_axis = br_max
	elif br_axis < a_min:
	    br_axis = a_min
	# 手刹轴
	if key_handbrake:
	    ha_axis += ha_inc
	else:
	    ha_axis -= ha_dec
	if ha_axis > a_max:
	    ha_axis = a_max
	elif ha_axis < a_min:
	    ha_axis = a_min
	# 离合轴
	if key_clutch:
	    cl_axis += cl_inc
	else:
	    cl_axis -= cl_dec
	if cl_axis > a_max:
	    cl_axis = a_max
	elif cl_axis < a_min:
	    cl_axis = a_min
	# 辅助
	if (autocut): # 自动断油
		if key_throttle and ashift_up_key:
			th_axis = a_min
		elif key_throttle and stimer > 0 and stimer < cut_min:
			th_axis = a_min
		elif key_throttle and stimer > cut_min and stimer < cut_max:
			th_axis += cut_rate - th_inc
	if (autoblip): # 自动补油
		if key_shiftdown:
			th_axis = a_blip
	# 刹车行程限制
	if bl_70:
		br_max = a_max * 0.4
	if bl_75:
		br_max = a_max * 0.5
	if bl_80:
		br_max = a_max * 0.6
	if bl_85:
		br_max = a_max * 0.7
	if bl_90:
		br_max = a_max * 0.8
	if bl_95:
		br_max = a_max * 0.9
	if no_bl:
		br_max = a_max
	if key_throttle_limit:
		th_max = th_limit
	else:
		th_max = a_max

#======== vjoy 轴与按钮映射(勿随便修改) ========#
v.x = int(round(steering))
v.y = th_axis
v.z = br_axis
v.ry = ha_axis
v.rx = cl_axis
v.setButton(0,key_shiftup)
v.setButton(1,key_shiftdown)
#v.setButton(2,key_light)
#======== 换挡计时 ========#
if ashift_up_key:
	stimer = 0
elif stimer < etimer: # 结束计时
	stimer += 1

#======== 调试 ========#
# 不调试时请注释掉,不然CPU使用率增加50%-80% 
#diagnostics.watch(v.x)	# steering
#diagnostics.watch(v.y)	# throttle
#diagnostics.watch(v.z)	# brake
#diagnostics.watch(v.ry) # handbrake
#diagnostics.watch(v.rx) # clutch
#diagnostics.watch(v.axisMax) # vjoy axis max range
#diagnostics.watch(stimer) # shifting timer

#======== 附录 & 例子 ========#
# vjoy轴: x, y, z, rx, ry, rz, slider, dial
# 键盘映射: keyboard.getKeyDown(Key.A); keyboard.getPressed(Key.A)
# 鼠标按钮映射: mouse.getButton(0); mouse.getPressed(1)
# 括弧内数字对应的鼠标按钮: 0 = 左键; 1 = 右键; 2 = 中键; etc.
# FreePIE有两种按键状态,第一种是按下按键后就执行相关代码并结束,第二种是按住按键时持续执行相关代码。
# 第一种的相关代码为: keyboard.getPressed() or mouse.getPressed()
# 第二种的相关代码为: keyboard.getKeyDown() or mouse.getButton()

#======== credits ========#
# 大部分vjoy轴逻辑代码源自此贴 https://www.lfs.net/forum/post/1862759
# 鼠标锁定代码源自 https://bytes.com/topic/python/answers/21158-mouse-control-python
# 代码重写、注释、自动断油、补油功能等 by threers(3Rs)
# last update: 2018-11